Dear,
This is my source code:
Code:
//file: test2.c
#include "test2.h"
struct Person2 {
Person* corePerson; //another struct, don't need to care
unsigned int height;
void (*notify_age) ();
};
void person2_notify_person_age () { //focus to this function, please
printf ("I am person2 and I received a notification\n");
return;
}
Person2* person2_create (unsigned int age, unsigned int height) {
Person2* tempPerson2;
tempPerson2 = malloc (sizeof (Person2));
tempPerson2->corePerson = person_create (age);
tempPerson2->height = height;
printf ("I am a 2nd newcomer with age: %d and height: %d\n", person_get_age(tempPerson2->corePerson),tempPerson2->height);
tempPerson2->notify_age = person2_notify_person_age; //assign the function pointer to real function
return tempPerson2;
}
//...
//some other functions
And this is my test:
Code:
#include "test2.h"
#include "test3.h"
int main ()
{
struct Person2* testPerson2;
struct Person2* tempPerson2;
int i = 0;
Person* testPerson;
testPerson = person_create (20);
testPerson2 = person2_create (30, 50);
person_set_age (testPerson, 20, testPerson2->notify_age); //call function pointer, ERROR here
return 0;
}