If two classes are defined “Parent” and “Child” then which is the correct type upcast syntax in C++?

If two classes are defined “Parent” and “Child” then which is the correct type upcast syntax in C++?
A. Parent *p=child;
B. Parent *p=*child;
C. Parent *p=&child;
D. Parent *p=Child();
 
Answer: c
Explanation: The syntax must contain the base class name first. So that the parent class object pointer can be declared. Then the object is assigned with the derived class object with & symbol. & symbol is added to get the address of the derived class object.
 

Tìm kiếm

Back
Top