I have a class L
simplified as follows :
class L
{
private:
C * _pc ;
public:
C * getc() const ; // getter
void setc(const C * ipc); //setter
~L()
{
delete _pc ;
}
};
where C
is another class.
I also have a helper class CHelper
simplified as follows :
class CHelper
{
C _c ;
CHelper(L & ic)
{
// 1st constructs _c (code omitted);
// then sets ic's _pc pointer member variable :
ic.setc(&_c);
}
};
I feel that there will be a problem with the deletion of _pc
somehow, without being sure. What about it ?
What are the flaws of such an approch ? How can I reach the same "functionality" (setting correctly a pointer member variable) with a correct approach ?