possibility to forbid use of "this"?
From: Ernst Murnleitner (mur-spam_at_awite.de)
Date: 01/07/04
- Next message: Dan Cernat: "Re: What does this code mean?"
- Previous message: John Carson: "Re: Linked list of object"
- Next in thread: tom_usenet: "Re: possibility to forbid use of "this"?"
- Reply: tom_usenet: "Re: possibility to forbid use of "this"?"
- Reply: Ron Natalie: "Re: possibility to forbid use of "this"?"
- Reply: Daniel T.: "Re: possibility to forbid use of "this"?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 7 Jan 2004 14:53:45 +0100
Dear Readers,
Is it possible to forbid conversion from this or use of this in general
except where it is explicitly wanted?
Reason:
I changed my program from using normal pointers to classes A, ...
typedef A * APtr;
to a shared pointer
typedef boost::shared_ptr<A> APtr;
Now, it crashes because of statements like this
// call
DoSomething(this);
....
// implementation
void DoSomething(APtr a)
{
// do nothing with a
}
Obviously, "this" is converted to a shared ptr locally. Outside the function
DoSomething() the shared ptr is destroyed and hence it tries to delete the
class where "this" points, too. This is clearly not wanted.
Greetings,
Many thanks in advance
Ernst
- Next message: Dan Cernat: "Re: What does this code mean?"
- Previous message: John Carson: "Re: Linked list of object"
- Next in thread: tom_usenet: "Re: possibility to forbid use of "this"?"
- Reply: tom_usenet: "Re: possibility to forbid use of "this"?"
- Reply: Ron Natalie: "Re: possibility to forbid use of "this"?"
- Reply: Daniel T.: "Re: possibility to forbid use of "this"?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]