[aspectc-user] Method introductions and slices

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Fri Mar 17 14:50:22 CET 2006


Hi Carsten,

Carsten V. Munk wrote:
> 
> Since I now get deprecated warnings, and get told to use slices when I 
> try to do this:
> 
> aspect Foo
> {
>    advice "Classname" : void foo()
>    {
> 
>    }
> };
> 
> - could you point me in the direction of how to do this properly then? I 
> tried following the language reference and do something like this:
> 
> aspect Foo
> {
>    advice "Classname" : slice class
>    {
>       void foo()
>       {
>       }
>    }
> };
> 
> - but that didn't seem to do the trick (errors). How are we supposed to 
> do method / field introductions into classes then?

the syntax of a slice declaration is very similar to the syntax of a 
template declaration. If you declare a class template or slice, the 
declaration has to end with ';'. That's all:

aspect Foo
{
    advice "Classname" : slice class
    {
       void foo()
       {
       }
    }; // <== you forgot this
};

You could also use --no_warn_deprecated to suppress the warnings. 
However, in the long term you should convert the code.

BTW, if foo() should become a public member, you should define the slice 
as follows:

    advice "Classname" : slice class // members of class slices are 
private by default
    {  public:
       void foo()
       {
       }
    };

or

    advice "Classname" : slice struct // members of struct slices are 
public by default
    {
       void foo()
       {
       }
    };

Regards,

Olaf



More information about the aspectc-user mailing list