B
Bit Byter
I have a 'root' object that serves as a container/parent for several
other objects like so:
class myRoot {
public:
myRoot();
virtual ~myRoot();
void* operator new(size_t);
operator delete(void*);
setChildX(X*);
setChildY(Y*);
setChildZ(Z*);
private:
myRoot(const myRoot&);
myRoot operator= (const myRoot&);
X* m_x ;
Y* m_y ;
Z* m_z ;
};
with the setChild... methods, is it better to write them as ff (using
setChildX as an example):
setChildX(X*); OR
setChildX(const X*); OR even
setChildX(const X&);
with the variable declarations (using variable of type X* as an
example),
should I declare the variable to be :
X* m_x OR
const X* m_x
The intended lifecycle for the child objects is as ff:
1). They are created and initialized OUTSIDE the parent
2). Once they are assigned to the parent object, they can no longer be
changed (i.e. const)
3). The parent destroys all its children upon parent's death (i.e. in
parent's destructor)
Given the intended life cycle, what is the best way of declaring the
methods and the variables that will hold the ptrs to the child objects?
other objects like so:
class myRoot {
public:
myRoot();
virtual ~myRoot();
void* operator new(size_t);
operator delete(void*);
setChildX(X*);
setChildY(Y*);
setChildZ(Z*);
private:
myRoot(const myRoot&);
myRoot operator= (const myRoot&);
X* m_x ;
Y* m_y ;
Z* m_z ;
};
with the setChild... methods, is it better to write them as ff (using
setChildX as an example):
setChildX(X*); OR
setChildX(const X*); OR even
setChildX(const X&);
with the variable declarations (using variable of type X* as an
example),
should I declare the variable to be :
X* m_x OR
const X* m_x
The intended lifecycle for the child objects is as ff:
1). They are created and initialized OUTSIDE the parent
2). Once they are assigned to the parent object, they can no longer be
changed (i.e. const)
3). The parent destroys all its children upon parent's death (i.e. in
parent's destructor)
Given the intended life cycle, what is the best way of declaring the
methods and the variables that will hold the ptrs to the child objects?