[aspectc-user] Pointcut for constructor

Danilo Beuche danilo.beuche at pure-systems.com
Mon Aug 11 13:07:02 CEST 2003

Iwan Birrer wrote:
> Hello,
> How does a pointcut for a constructor look like? I have the following for a
> class 'Receiver':
> pointcut receiverConstructor() = "Receiver(...)";
> Unfortunately this does not work...
> Thanks for any help
> Iwan
> _______________________________________________
> aspectc-user mailing list
> aspectc-user at aspectc.org
> http://www.aspectc.org/mailman/listinfo/aspectc-user

short answer: it is not possible to match a constructor with a pointcut 
expression in the current version of AspectC++ (0.7).

longer answer: The way aspects are implemented in AspectC++ does not 
allow for weaving aspects into constructor/destructor code. Aspects are 
realized as separate methods which call the original code if necessary.
This scheme does not work for constructors. It is not possible to call 
the old constructor directly (constructors are called implicitly be 
compiler generated code only).

If you write own software or are able to modify the original source, you 
could introduce an additional method, e.g. "create( )" which does the 
real work. This can be matched with an pointcut expression and thus 
modified. I know this is ugly, but maybe someone has an idea how to 
improve this...

aspect Foo
	pointcut rCreate() = "R::create(...)";

class Bar
	Bar() { create() };
	void create() { do_something(); }

Danilo Beuche                           Phone: +49-391-54456910
pure-systems GmbH                       Fax:   +49-391-54456990

More information about the aspectc-user mailing list