[aspectc-user] reset tjp->that()?
Daniel Lohmann
daniel.lohmann at informatik.uni-erlangen.de
Fri Dec 8 17:06:02 CET 2006
Hi Yan,
I am afraid what you are trying to achieve is not possible.
> //the C++ code
> ClassA *p = new ClassA();
> p->DoSomething();
> p->Release();
> //now i want to set p=NULL with AOP
In C++ the object instance pointer (this) is always passed by-value.
Technically, it is passed as a "hidden" first parameter:
class A {
void Release();
};
becomes (technically) something such as
void ClassA::Release( ClassA* this ) {
// this is by-value parameter
}
The object reference inside some method (this) is a copy of the original
parameter. The same holds for the value returned by tjp->that() in
advice code, it is another value copy of the originally passed instance
pointer. It is not possible to affect the "original" from advice code.
Side node:
The common C++ idiom to invalidate the reference when destroying an
instance is to use a non-member function:
// Template, works for any class that offers a Release() method
template< class T > void Release( T*& _this ) {
_this->Release(); // destroy
_this = 0; // invalidate
}
//the C++ code
ClassA *p = new ClassA();
p->DoSomething();
Release(p);
// now p == 0
Daniel
Yan Mao schrieb:
> Hello there,
> I'd like to ask, if it is possible to reset the pointer tjp->that() of NULL?
>
> say i have an object pointer, after i use it, i release it, and i wnat to set it as NULL with AOP.
>
> //the C++ code
> ClassA *p = new ClassA();
> p->DoSomething();
> p->Release();
> //now i want to set p=NULL with AOP
>
> //the AOP Code:
> advice call("% ...::Release()"):after(){
> tjp->that()=NULL;
> }
>
> but i got the error C2106, "=": Linker Operand muss ein L-Wert Sein.
>
> regards,
>
> Yan Mao
>
>
More information about the aspectc-user
mailing list