[aspectc-user] global definitions

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Fri Jun 18 11:42:20 CEST 2004


pdm-steve schrieb:
> Seems, I found it by myself.... it was much easier than exepcted:
> aspect myAspect{
>     TDataContainer* DataContainer;
>     advice execution("% main(...)") : around() {
>         DataContainer = new TDataContainer();
>         tjp->proceed();
>         delete DataContainer;
>     }
> }
> greets,
> Steffen K├Ąthner

I didn't expect that this is what you were looking for. For which 
purpose do you need the pointer "DataContainer"? Do you want to access 
the object from within "main()"? If you want that, it would be more 
convenient to declare it in the global scope in the aspect header file. 
Otherwise you have to reference it with 
"myAspect::aspectof()->DataContainer" which is not very elegant ;-).

Objects, types, etc. declared in an aspect header are visible in all 
translation units that are affected by the advice of the aspects defined 
in the particular header.

Another improvement would be to declare the TDataContainer as a local 
variable in the advice code body. This makes sure that you don't forget 
the "delete .." and is also more efficient.

Greeting from the ECOOP in Oslo, Norway,


More information about the aspectc-user mailing list