Object creation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Object creation

class A{}; class B : public A{}; int main() { //Why can we write this: A* obj = new B; //and can't do this: B*obj = new A; //error return 0; }

2nd Jan 2019, 7:30 PM
JanSeliv
JanSeliv - avatar
1 Answer
+ 2
Class A is like a model for class B. B has just new features. For example, you have a mother class Vehicle (A) and a derived class Motorbike (B) : all Motorbike are Vehicle but all Vehicle aren't Motorbike.
2nd Jan 2019, 10:10 PM
Théophile
Théophile - avatar