[aspectc-user] Re: Problem with introducing methods ...
Matthias Urban
matthias.urban at pure-systems.com
Thu Aug 26 11:23:24 CEST 2004
Hi,
Masoud Mansouri-Samani wrote:
> Hi,
>
> I have a problem with introducing methods in the following simple
> example. I am using ac++ version 0.9pre1 on Linux. Here is the command
> line and results:
>
> $ ac++ -a test.ah -p . -c test.cpp
> test.ah:12: error: invalid member declaration near token `*'
> test.ah:17: error: `Employer' has no member named `getAdmin'
>
> Where test.ah is:
>
> class Employer {
> };
>
> class Person {
> public:
> Employer employer;
> };
>
> aspect Test
> {
> private:
> advice "Employer": Person *admin;
>
> public:
> advice "Employer": Person *getAdmin() { return admin; }
> advice "Person": Person *getEmployersAdmin() {
> return employer.getAdmin();
> }
> };
>
> And test.cpp is:
>
> int main(int argc, char *argv[]) {
> return 0;
> }
>
> What am I doing wrong? What is wrong with the introduction of "Person
> *admin" on line 12?
> Why does it complain about getAdmin() not being a member of Employer on
> line 17. I've just introduced it!
>
> I would appreciate any help on solving this problem.
>
> Regards
>
> Masoud
Your aspect doesn't work because you try to introduce something that
depends on a type that is not known at the join point. I think, the
weaving result shall look like this:
class Employer {
Person *admin;
...
};
class Person {
public:
Employer employer;
};
But that cannot be parsed. The solution is to simply add a forward
declaration for Person at the top of test.ah. You also should put the
declarations of Person and Employer into own header files so that the
aspect declaration (and its dependencies) are separated from the code
you want to weave.
employer.h:
-----------
class Employer {
};
person.h:
---------
#include "employer.h"
class Person {
public:
Employer employer;
};
test.cpp:
---------
#include "person.h"
int main(int argc, char *argv[]) {
return 0;
}
test.ah:
--------
class Person;
aspect Test {
advice "Employer": Person *admin;
public:
advice "Employer": Person *getAdmin() { return admin; }
advice "Person": Person *getEmployersAdmin() {
return employer.getAdmin();
}
};
This is the recommended way of using AspectC++. I hope this helps a
little bit.
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/20040826/9b3dbfd7/attachment.bin>
More information about the aspectc-user
mailing list