Object creation | Sololearn: Learn to code for FREE!


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; }


1/2/2019 7:30:35 PM


1 Answer

New Answer


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.