T
tech
Hi, Whenever i have a class that contains references to other classes
i keep
end up doing the below. However it doesn't seem so safe or elegant.
How do the
pros initialise subobjects, any ideas to improve the below would be
welcome.
/.h file
class A
{
public:
A();
~A();
private:
SomeMethod();
obj1* pobj1;
obj2* pobj2;
obj3* pobj3;
obj4* pobj4;
};
/.cpp file
A::A()
{
pobj1 = new obj1;
pobj2 = new obj2;
pobj3 = new obj3;
pobj4 = new obj4;
}
A::SomeMethod()
{
pobj1->doSomething();
etc
}
A::~A()
{
delete pobj1;
delete pobj2;
delete pobj3;
delete pobj4;
}
i keep
end up doing the below. However it doesn't seem so safe or elegant.
How do the
pros initialise subobjects, any ideas to improve the below would be
welcome.
/.h file
class A
{
public:
A();
~A();
private:
SomeMethod();
obj1* pobj1;
obj2* pobj2;
obj3* pobj3;
obj4* pobj4;
};
/.cpp file
A::A()
{
pobj1 = new obj1;
pobj2 = new obj2;
pobj3 = new obj3;
pobj4 = new obj4;
}
A::SomeMethod()
{
pobj1->doSomething();
etc
}
A::~A()
{
delete pobj1;
delete pobj2;
delete pobj3;
delete pobj4;
}