The destruction of a sub instantiated obj that I’m pointing too.
This is a pseudo code example, don’t get all bent if I forgot a
semicolon etc for something like some of you do. This will probably not
compile, just an example to explain.
Problem, how do I properly destruct the object that msg is pointing to
in main? O I have to figure out what type of msg it is pointing to and
explicitly call that destructor?
class MsgCreator
{
Msg *MsgCreator::Cr eateMsg(int msgtype)
{
if (msgtype ==1)
return new msg1();
else
return new msg2();
}
class Msg
{
}
class msg1 : public msg
{
}
class msg2:public msg
{
}
main()
{
Msg *msg;
MsgCreator *m = new MsgCreator();
msg = m-> CreateMsg(1);
delete msg;//does not seem to work, did not call the destructor
}
Thanks,
Frank
This is a pseudo code example, don’t get all bent if I forgot a
semicolon etc for something like some of you do. This will probably not
compile, just an example to explain.
Problem, how do I properly destruct the object that msg is pointing to
in main? O I have to figure out what type of msg it is pointing to and
explicitly call that destructor?
class MsgCreator
{
Msg *MsgCreator::Cr eateMsg(int msgtype)
{
if (msgtype ==1)
return new msg1();
else
return new msg2();
}
class Msg
{
}
class msg1 : public msg
{
}
class msg2:public msg
{
}
main()
{
Msg *msg;
MsgCreator *m = new MsgCreator();
msg = m-> CreateMsg(1);
delete msg;//does not seem to work, did not call the destructor
}
Thanks,
Frank
Comment