[aspectc-user] adding variables and using them
Jamal Siadat
siadat at cpsc.ucalgary.ca
Fri Jul 15 03:20:30 CEST 2005
Hi,
I have a class A whcih I have extended it with a single variable int x,
using an aspect. now I want to initialize this variable only when a
certain method a in class A is invoked:
advice call("% A::a(...)") : before(). which I included in a second aspect
A2. I cant just initialize x in this advice since it is not part of A2
resulting in me having to extend TWO from A( aspect A2: public A). The
issue here is that the initialized x in A2 is not part of A. so when the
initialization is performed in A2, the object of A which called this
method does not have x initialized therefor yielding the wrong result. Can
anyone help me with this one please?
A more code based explanation:
aspect Cache {
public:
pointcut shapes() = "A";
advice shapes() : int x;
};
aspect A2 :public A {
advice call("% A::a(...)") : around() {
x=0;
}
};
int main () {
A a;
a.a ("hello", 3.14);
cout <<"x is: "<<a.x<<endl;
}
OUTPUT: x is: 134515452 , but i need to get the 0 that I initialized it
to. Is there anyway to get this result? If there is anyway to write A2
without extending A, it should work. but i cant seem to think of any.
sorry for the silly questins and thaks for all your help,
Jamal
More information about the aspectc-user
mailing list