possibility to forbid use of "this"?

From: Ernst Murnleitner (mur-spam_at_awite.de)
Date: 01/07/04


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