Lessons learned on virtual
virtual usage
Child class doesn't need virtual keyword for virtual function, even if defined it's redundant
the parent class should contain same function signature as child class also contains the same function signature but parent class should declare it as virtual.
function signature same no of arguments , same sequence of types and same function name.
Object type will decide which function to call
When you are allocation object with new then only virtual destructor works, if you allocating object on stack then it will automatically destroy child obj first then parent obj.
http://www.vishalchovatiya.com/part-3-all-about-virtual-keyword-in-c-how-virtual-destructor-works/
the parent class should contain same function signature as child class also contains the same function signature but parent class should declare it as virtual.
function signature same no of arguments , same sequence of types and same function name.
Object type will decide which function to call
When you are allocation object with new then only virtual destructor works, if you allocating object on stack then it will automatically destroy child obj first then parent obj.
http://www.vishalchovatiya.com/part-3-all-about-virtual-keyword-in-c-how-virtual-destructor-works/
Comments
Post a Comment