Ask a Question related to UNIX Programming, Design and Development.
-
Frank #1
The destruction of a sub instantiated obj that I’mpointing too.
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::CreateMsg(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
}
Frank Guest
-
Bug when events are instantiated by AS3 instead of MXML
In example 1 the events rollOver and rollOut are initialized using MXML. When you run the example you can see when you rollOver the Canvas the... -
Finding out if web service instantiated object
I have a vb class that manages all of my session and query stirng parameters plus the user login. I would like to use it within my web web service... -
[PHP-DEV] [PATCH] Two bugs in variable destruction
Hello. There are two bugs that show when code is executed from an object destructor and PHP is compiled in debug mode. Both bugs cause the... -
Sudden self-destruction of SuSE 8.2 installation?
Hi, I didn't see it coming, out of the blue my SuSE 8.2 installation appears to be completely ruined. What I did when it happened is to mount a... -
Height function and instantiated objects
Hi I was just wondering if Flash MX has a patch on instantiated objects and the hieght function.Ive been sought of recreating the wheel with some... -
Marc Rochkind #2
Re: The destruction of a sub instantiated obj that I’m pointing too.
On Thu, 07 Aug 2003 17:26:13 GMT, Frank <fgeck@optonline.net> wrote:
[snip]> The destruction of a sub instantiated obj that I’m pointing too.
>
Response:
1. This belongs in a C++ newsgroup, not here.
2. Hard to read the psuedo code, but I think the problem is that you should
make the destructors virtual. Look this up in a good C++ book and it will
explain why that's important.
--Marc
Marc Rochkind Guest
-
Joe Halpin #3
Re: The destruction of a sub instantiated obj that I’m pointing too.
Frank <fgeck@optonline.net> writes:
I don't want to appear to be getting all bent, but there aren't any> 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::CreateMsg(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
destructors in what you show, so it's hard to say what the problem
is. Also, Marc is correct in suggesting that this would be better
asked on a C++ newsgroup.
I suspect he's also right about needing a virtual destructor, but it's
hard to tell from what's given above. It wouldn't have been that much
additional effort to post something that actually compiles and
runs. This works as expected with g++
#include <iostream>
class Msg
{
public:
virtual ~Msg() {cout << "Msg::~Msg()\n";}
};
class msg1 : public Msg
{
public:
~msg1() {cout << "msg1::~msg1()\n";}
};
class msg2:public Msg
{
public:
~msg2() {cout << "msg2::~msg2()\n";}
};
class MsgCreator
{
public:
Msg *CreateMsg(int msgtype)
{
if (msgtype ==1)
return new msg1();
else
return new msg2();
}
};
main()
{
Msg *msg;
MsgCreator *m = new MsgCreator();
msg = m->CreateMsg(1);
delete msg;
}
Joe
Joe Halpin Guest



Reply With Quote

