E
Ernst Murnleitner
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
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