T
tech
Hi, thanks for help in previous post. I've made the class objects i
need data members so
i now initialise in constructor. However some of my subobjects need to
have a reference to their
owner object.
Can i do the following then ie pass *this in the constructor of A, i
was concerned maybe the
A object is not fully constructed. If this is not way to do how to do?
/.h file
class A
{
public:
A();
~A();
private:
obj1 myobj1;
};
/.cpp file
A::A()
: myobj1(*this) <- CHANGE MADE HERE
{
}
A::~A()
{
}
Obviously constructor of obj1 takes reference to A
class obj1
{
private:
obj1& m_obj;
};
obj1(A& a):m_obj(a)
{
}
need data members so
i now initialise in constructor. However some of my subobjects need to
have a reference to their
owner object.
Can i do the following then ie pass *this in the constructor of A, i
was concerned maybe the
A object is not fully constructed. If this is not way to do how to do?
/.h file
class A
{
public:
A();
~A();
private:
obj1 myobj1;
};
/.cpp file
A::A()
: myobj1(*this) <- CHANGE MADE HERE
{
}
A::~A()
{
}
Obviously constructor of obj1 takes reference to A
class obj1
{
private:
obj1& m_obj;
};
obj1(A& a):m_obj(a)
{
}