-2

I don't understand why this error continues to pop. This is the function i'm trying to build: /person is a struct. Person* is a pointer.

void(*CreateNext)(struct Person *this, int isNextNext, ...)
    {
        Person* person;
        person = (Person*)malloc(sizeof(Person));
        person = CreatePerson(person);
        this->next = person;
    }

The error is on the first line and on the '{'

//This is the struct:
struct Person {
    char* name;
    int id;
    int numOfKids;
    char** kids;
    struct Person* next;
    void (*Print)(struct Person* this);
    void (*KillNext)(struct Person* this);
    struct Person* (*SelfDestruct)(struct Person* this);
    void (*CreateNext)(struct Person* this, int isNextNext, ...);
};
CS student
  • 33
  • 1
  • 1
  • 4

1 Answers1

0

You are declaring a variable (a pointer to a function) outside the scope of a function.

You want CreateNext to be the name of a function, not the name of a variable. The declaration should be

void CreateNext(struct Person *this, int isNextNext, ...)
    {
        Person* person;
        person = (Person*)malloc(sizeof(Person));
        person = CreatePerson(person);
        this->next = person;
    }

BTW, you shouldn't cast the return of malloc(). Casts are evil.

One Guy Hacking
  • 1,176
  • 11
  • 16