[aspectc-user] unknown error?
Olaf Spinczyk
Olaf.Spinczyk at informatik.uni-erlangen.de
Thu Jun 30 09:32:07 CEST 2005
Hi,
Jamal Siadat wrote:
> Hi,
> I tried making up this silly example just to address an issue that I had
> with the Ac++ project that I've been working on but I keep getting an
> error that I'm not sure how to deal with.
>
> I have two classes A and B.
>
> #ifndef __A_H_
> #define __A_H_
> class A {
> public:
> int j;
> int a(const char *name, float b);
> private:
> int p;
> };
> #endif
>
>
> #ifndef __B_H_
> #define __B_H_
> #include "A.h"
> class B {
> public:
> int j;
> int a(const char *name, float b);
> private:
> int p;
> };
> #endif
>
>
> as you can see A is included in B. I have devised an aspect to add a
> member of type B to A.
>
> #ifndef __asp_ah__
> #define __asp_ah__
> #include <iostream.h>
> #include "B.h"
> using namespace std;
> //int jeee ( int r, int y){ int e = r+y; return e;}
>
> aspect asp {
> pointcut calls()= "A" ;
> advice calls() : B Z;
>
> };
>
> #endif
>
> But unfortunatly I keep getting : asp.ah:10: error: invalid member
> declaration near token `Z'. I just want to add B to it. I have tried
> making Z a pointer as well but I still keep getting: asp.ah:10: error:
> invalid member declaration near token `*'. Is there anyway to solve this
> issue? I know this is just a toy example but it will really help.
>
> Thanks in advance,
the problem is that your aspect tries to create a cyclic dependency
between the classes A and B. For some reason, which is not clear from
your code, B depends on the definition of A. Otherwise you wouldn't
include A.h. Now you want to introduce an B instance into A, which means
that A needs the definition of B. Such cyclic dependency is not
supported by normal C++ and AspectC++ either.
If it is acceptable for you, you could work around the problem with the
pointer solution, i.e. you introduce a pointer to B instead of a B
instance. I know that you tried this already, but probably there was
something wrong. Replace the #include "B.h" with a forward declaration
of class B in your aspect header. Then it should work.
As an alternative you could also try to move all the code of B that
depends on A from the header file B.h into an implementation file B.cc.
Then you can remove the #include "A.h" from "B.h" and your introduction
should also work with an instance of B.
Just for a better understanding of the weaving process: When ac++
introduces something into a class that is defined in a header file, it
generates and inserts an #include directive at the beginning of this
header file. which includes the respective aspect header. This is to
make sure that the type of the introduced object is known in the target
header file. Therefore, in your example, A.h includes the aspect header,
which includes B.h, which includes A.h, ...
I hope this helps,
Olaf
PS: if you have a minute, please tell me more about your project ...
More information about the aspectc-user
mailing list