[aspectc-user] non-inline introduction

Panu Bloigu panu.bloigu at gmail.com
Wed Mar 26 10:54:49 CET 2008


Hi,

arnd-hendrik.mathias at nefkom.net wrote:
> Hi,
> 
> Zitat von Panu Bloigu <panu.bloigu at gmail.com>:
> 
>> Hello.
>>
>> arnd-hendrik.mathias at nefkom.net wrote:
>>> So, I cannot add a slice of a static member to a virtual class, at all?
>>
>> I can't see any reason that would prevent you from doing this.
> 
> So, is it still virtual if there's an implementation for a virtual ctor?

C++ does not recognize such a thing as 'virtual class' (a virtual base 
class, OTOH, is entirely different thing). A class can be *abstract* if 
it contains at least one pure virtual method. If a class is abstract, an 
instance of the class can not be created, regardless whether there is an 
constructor explicitly defined or not (in fact, C++ compiler creates a 
default ctor in any case). So adding a definition of an empty ctor to a 
class that has no explicitly defined ctor, changes nothing. But by doing 
this you can create a translation unit for the class.

A constructor can not be virtual -- it does not make sense.

> 
> 
>> In regard to your other problems, I can not give any advice at the
>> moment. Perhaps, if you suppled at least the code in devices.ah?
> 
> What I cited was essentially the complete code of devices.ah:
> 
> 
> slice class Devcounter
> {
>    public : static unsigned int counter;
> };
> 
> slice unsigned int Devcounter::counter = 0;
> 
> aspect Counter
> {
>    pointcut devices () = derived ( "Device" );
>    pointcut main () = execution ( "% main (...)" );
> 
>    advice "Device" : slice Devcounter;

Until this point everything seems correct to me, except for the fact 
that you haven't surrounded your aspect header with include guards. Try 
adding include guards to devices.ah.

>    advice main () : before ()
>    {
>       cout << "counter = " << Devcounter::counter << ";\n";

Here, outside of the slice, you don't refer to the slice members as the 
members of the slice (of course, this doesn't apply to defining of the 
slice members). Instead, you refer to then like you would if the slice 
was already added to the target class. So, here it would be Device::counter.

However, this requires you to include the header "Device.h" into this 
aspect.

>    };
> };

-- Panu.






More information about the aspectc-user mailing list