[aspectc-user] syntax question

Law, Colin colin.law at epid.eurotherm.co.uk
Wed Feb 13 14:09:59 CET 2002


> > On the requirement for the helper function access_A, I 
> tried it without the
> > helper function, directly accessing the pointer in before() 
> and it was OK.
> > Can you explain this issue in more detail?
> 
> Ok, look at the code...
> --------------------------------------------------------------
> ---------------
> class A;
> 
> aspect O
>  {
>    void access_A(A* aptr);
> 
>    advice that(aptr) && execution ("void %::a()") :
>       void before (A *aptr)
>       { access_A(aptr);
>       }
>  };
> 
> class A
>  {
>    public:
>       int i;
>       A() { i = 4711; }
>       virtual void a () {}
>  };
> 
> // B and C as show above
> 
> void O::access_A (A *aptr)
>  { cout << "before a(), i is " << aptr->i << endl;
>  }
> 
> // main as show above
> --------------------------------------------------------------
> ----------------
> Without access_A we would try to use aptr->i in the advice, 
> before class A is 
> defined completely. This wouldn't compile. Alternatively we 
> could define A 
> before the aspect but then the generated code in A::a() would 
> try to call the 
> advice, which is not defined yet. This wouldn't compile as 
> well. It is a 
> cyclic access relation. I don't know why there is no problem 
> in your case. Do 
> you access an attribute or function of a base class of "class A"?
> 

I understand the problem now, the reason I am ok without the helper function
is that the base class on which I am calling the function is of type CWnd,
which is a class provided by MFC. I am therefore merely including the header
before the aspect definition.  Since the header (and the code for CWnd) are
not part of the set of files to be compiled individually by ac++ then the
advice code is not generated for CWnd and there is no problem.  This is ok
for me because I would not expect to need to apply aspect code to the
standard classes provided by microsoft. (I think).

Colin Law



More information about the aspectc-user mailing list