lundi 30 mars 2015

How to allocate memory for object of the derived class by pointer of the base class using malloc?


For example there is a chain



class A
{
int a;
int b;
public:
A();
};

class B: public A
{
int c;
char b;
public:
B()
};


In ordinary way to to create an object of the derived class we can use this form



A* ptr = new B()


How to do the same using malloc ?




Aucun commentaire:

Enregistrer un commentaire