Hello,
I am trying to learn a little about inheritance in C through an article I found on the web at:
Inheritance and Polymorphism in C - CodeProject
There is one thing I don't understand. In this article, there are two structures... a base struct called "Person" and a derived struct called "employee". The intent is to be able to fetch functions in the employee module via either a person pointer type or an employee pointer type. Also, either object can have access to any data members via two linking members ... pDerivedObj* and pBaseObj*. Atleast this is what I think. Please correct me if I am wrong. My concern is the following.
If you go to p. 6 of 8, under the title "Structure of the employee object", we see a diagram of the two strucutres side by side. Both structures have a member pointing to the other structure. So in other words, the Person struct has pDerivedObj pointing to the employee object and the employee struct has pBaseObj pointing to the person object.
The pDerivedObj is assigned the address of the employee object at the following line of the new_Emplyee() function:
pObj->pDerivedObj = pEmpObj;
But what I don't understand is that I don't see where the addresss of the person object is assigned to the pBaseObj pointer member of the employee object??? The diagram shows the arrow going from the pBasePObj* to the person struct, but I don't see where the code does this assignment.
Can someone please help me, I have looked over the code in this article many times and I still just don't see it.
All help appreciated.
Regards
Robert