[aspectc-user] Introducing/overloading constructors.

Matthias Urban matthias.urban at pure-systems.com
Tue Aug 24 13:28:28 CEST 2004


Hi,


Jean J wrote:
> Hi,
> 
> Is there a way to overload a constructor of a class in
> AspectC++ ?
> 
> I am trying to introduce a new constructor into one of
> my classes. In my aspect file I write :
> 
> aspect MYASPECT {
> 
> public:
> 
> advice "MyObject":
>   MyObject(int x, int y, int z) {
>     // object constructor
>   }
> };
> 
> but ac++ generates the following error:
> 
> invalid member declaration near token `int'
> 
> Is there something wrong with my advice. And is it
> possible to overload / introduce new constructors into
> classes in aspectc++ ?
> 
> 10nx


Introducing constructors and destructors is not yet directly supported. 
Though, it is possible to trick ac++ so that a constructor is introduced 
into a class. You can do this with the above aspect but you have to 
ensure that MyObject is not yet known as class to ac++, i.e. there must 
not be an #include "MyObject.h" or the class declaration of MyObject 
itself before the aspect declaration. ac++ will then interpret 
MyObject(int,int,int) as an ordinary member function instead as a 
constructor (as it is in the context of class MyObject) and introduces 
it like any other member function. This is only a trick and it doesn't 
work for destructors because ~Name is not a valid function name.

The reason for all this is because ISO C++ defines constructors and 
destructors not to have names! So you also can't write a pointcut 
expression matching constructors/destructors. But a solution for this is 
already in work.


Matthias

-- 
Matthias Urban                          Phone: +49-391-544569-32
pure-systems GmbH                       Fax:   +49-391-544569-90
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3136 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://www.aspectc.org/pipermail/aspectc-user/attachments/20040824/e30b5d26/attachment.bin>


More information about the aspectc-user mailing list