Skip to content

defination of struct #13

@JohnTargaryen

Description

@JohnTargaryen

Morning +7;

struct person {
    person() {
        for (int i = 0; i < 1000; i++)
        friends[i] = 9999;
        id = idcounter;
        idcounter++;
    }
    bool ifisfriend(int id) {
        for (int i = 0; i < 1000; i++) {
            if (friends[i] == 9999)
            return false;
            if (friends[i] == id)
            return true;
        }
    }
    void makefriend(int id) {
        friends[friendcounter] = id;
        friendcounter++;
    }

    void breakup(int id) {
        for (int i = 0; i < 1000; i++) {
            if (friends[i] == id)
            friends[i] = 9999;
        }
    }

    void setid() {
        id = 9999;
    }

    int getid() {
        return id;
    }
    static int friendcounter;
    int friends[1000];
    int id;
    static int idcounter;
};

My struct defination is above, but the gdb tells me that Segmentation fault occured in the scope below. why is that, could you explain it to me ? THX.

 person mike, jack, lily, carson, sucie;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions