In reply to dave_59:
Thanks for the reply Dave,
Please consider the following portion of the code:
P1 = P2; // P1 has a handle to a My_packet object
P1.printA; // displays 'BasePacket::A is 1'
P1.printB; // displays 'My_Packet::B is 4' latest derived method
P2.printA; // displays 'My_Packet::A is 3'
P2.printB; // displays 'My_Packet::B is 4'
why would P1.printB display 4 instead of 2?
How come the base class handle is able to access derived class variable values?
If B in derived class is considered as a member that overrides B in the base class, then when printing B using a virtual function should surely print ‘My_Packet::B is ’ but should not be able to access the derived class variable B. If I try to print variable C in the virtual function in the derived class that would be a run time error. I am assuming the same rule applies to variable B in the derived class. Please let me know what I am missing.