G
Glenn Serpas
I have Class A and Class B .. Class B has a private member that is a pointer
to a Class A object.
private:
B *mypointer ;
I instantiate the A object
A* myobject new = A();
How do I tell it to instantiate it's member mypointer ? I've tried several
options I've read about in my C++ book and on the web. The solutions I
found were to add the following to the contructions declaration in the
class header. However, it will not compile.
public:
A() { mypointer = new B() ; }
I've also tried adding instantitating the object in the contructor
implementation. This will compile, but will crash during execution.
A::A()
{
B* mypointer = new B() ;
}
I can only instantiate the mypointer if it is not a pointer (ie B
myBobject I simply add it to the constructor implementation for class A.
A::A() : myBobject()
{
}
Hopefully someone reading this message will have an approach that will work
for me. Thanks.
Glenn
to a Class A object.
private:
B *mypointer ;
I instantiate the A object
A* myobject new = A();
How do I tell it to instantiate it's member mypointer ? I've tried several
options I've read about in my C++ book and on the web. The solutions I
found were to add the following to the contructions declaration in the
class header. However, it will not compile.
public:
A() { mypointer = new B() ; }
I've also tried adding instantitating the object in the contructor
implementation. This will compile, but will crash during execution.
A::A()
{
B* mypointer = new B() ;
}
I can only instantiate the mypointer if it is not a pointer (ie B
myBobject I simply add it to the constructor implementation for class A.
A::A() : myBobject()
{
}
Hopefully someone reading this message will have an approach that will work
for me. Thanks.
Glenn