[aspectc-user] Defining structure inside advice code
Bartosz Blimke
masb at chorwacja.com
Mon Jun 7 14:38:02 CEST 2004
Hi,
C++ doesn't allow to have nested definition of functions,
thats mean it will not allow to make definition like this.
int func1()
{
int func2()
{
return 5;
}
return func2();
}
Simple solution for this problem is to pack the nested
function into structure
int func1()
{
struct aa
{
int func2()
{
return 5;
}
} simpleStructInstance;
return simpleStructInstance.func2();
}
C++ compiler compiles it without problems.
Problem is with ac++ advice code:
//main.cpp
#include <stdio.h>
void func () {
printf ("func\n");
}
int main (int argc, char * argv[]) {
func ();
return 0;
}
//end of main.cpp
aspect Aspect {
pointcut methods() = execution("% func()");
advice methods() : before()
{
struct simpleStruct{
int methodOfStruct()
{
return 0;
}
} instance;
instance.methodOfStruct();
}
};
Linking...
main.obj : error LNK2005: "public: int __thiscall `public: void __thiscall
Aspect::__a0_before(void)'::`2'::simpleStruct::methodOfStruct(void)"
(?methodOfStruct at simpleStruct@?1??__a0_before at Aspect@@QAEXXZ at QAEHXZ)
already defined in TestAspectProject_LinkOnce.obj
Debug\TestAspectProject.exe : fatal error LNK1169: one or more multiply
defined symbols found
The same problem is with after().
When I use around() problem is only if I use tjp->proceed()
inside the body of advice code.
If the structure is defined inside aspect body but outside the
advice body problem dissapear.
Is it another problem linked to vc++ compiler, or ac++ bug ?
Greets,
Bartosz Blimke
More information about the aspectc-user
mailing list