I want to initialize an object A in class B but I want to initialize the object as a pointer. For some reason the code doesn't call the constructor for class A.
class A
{
protected;
int x;
int y ;
public:
A()//constructor
{
x=25;
y=17;
cout << "x: " << x << endl;
cout << "y: " << y << endl;
}
};
class B
{
protected:
A*a;
public:
B():a(NULL){}
};
The code works fine if I initialize an object of as " A a", but I want to assign an of objects of class A on the heap.