w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
C++ Final exam study material

Since B is derived from A, every B is an A. So pa can point to an object of type A or any derived type. But the type of object doesn't change, so b is still of type B and behaves as such. The only restriction is that, since it's being referenced by a pointer to A, you can only reference the methods and member variables that are declared in the base class A.

For an explanation of why C++ works this way, look for a discussion on vtables.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.