I have a very general question, related to dynamic_cast in c++: Let's assume we have the following classes:
class Father{
public:
Father(...); // this is constructor
//.....
//.. Whatever code in here, not important
~ Father(); //destructor
protected:
// some protected variables
} // end of class Father
class Son:public Father {
public:
Son(...); // this is cnostructor
//.....
//.. Whatever code in here, not important
~ Son(); //destructor
protected:
// some protected variables
} // end of class Son
class Another{
public:
Another(...); // this is constructor
//.....
//.. Whatever code in here, not important
~ Another(); //destructor
AnotherMethod(Father* fatherOpj,......) //
} // end of class Another
And let's say the method "AnotherMethod" do the next:
AnotherMethod(Father* fatherOpj,......)
{
Son *sonObj = dynamic_cast<Son*>(fatherOpj);
// using sonObj
}
While in the main we do the following:
Son* son1=Null;
//...
son1 = new Son(.....);
//....
AnotherMethod(son1,....);
Now, I'm wondering about the next issue: that way- when we call AnotherMethod with a pointer of type Son*, while in its signature there's Father*- will we lose the fields/members in son (which father doesn't have) or that by doing the dynamic_cast we will be able to have them (with the right values inside them)?!