M
Maurice
Hi,
We are implementing some wrappers in C++ according to the Adapter
Pattern. The classes and their methods in the Adaptee classes
(open-source library) have already the interface that we like, but we
want to rename them so we want to implement the Adapter classes in
such a way that we only have to rename the Adaptee classes. We prefer
to use #define's because of the better run-time performance, in stead
of implementing wrapper functions.
In our case we have an Adaptee class that looks like this (simplified
example):
class Adaptee
{
public:
int Method1(int in);
int Method2(void);
private:
int Attribute;
};
This Adaptee class is implemented and build in a library.
Now we create an Adapter class (derived from a (abstract) Target
class) that is defined in the .h-file and looks like this (simplified
example):
class Adapter : public Target
{
public:
int my_method_1(int in);
int my_method_2(void);
};
In the corresponing .cpp-file we include this .h-file and implement
the Adapter class in the following way:
#define Adapter Adaptee
#define my_method_1 Method1
#define my_method_2 Method2
If we build our Adapter and Target classes into a library, everything
goes fine. There are no compile or link errors.
Now we use our self-created library in an application, but then we got
linking errors to tell us that we have: "unresolved external symbols"
on the methods that are part of the Adapter classes. Our application
looks like this (simplified example):
int main(int argc, char *argv[])
{
int Result;
Adapter MyAdapter;
Target *pMyTarget = &MyAdapter;
Result = pMyTarget->my_method_1(0);
Result = pMyTarget->my_method_2();
return Result;
}
So my question is now. Can someone explain me what we are doing wrong
and how we can solve these linking errors?
Thanks,
Maurice
We are implementing some wrappers in C++ according to the Adapter
Pattern. The classes and their methods in the Adaptee classes
(open-source library) have already the interface that we like, but we
want to rename them so we want to implement the Adapter classes in
such a way that we only have to rename the Adaptee classes. We prefer
to use #define's because of the better run-time performance, in stead
of implementing wrapper functions.
In our case we have an Adaptee class that looks like this (simplified
example):
class Adaptee
{
public:
int Method1(int in);
int Method2(void);
private:
int Attribute;
};
This Adaptee class is implemented and build in a library.
Now we create an Adapter class (derived from a (abstract) Target
class) that is defined in the .h-file and looks like this (simplified
example):
class Adapter : public Target
{
public:
int my_method_1(int in);
int my_method_2(void);
};
In the corresponing .cpp-file we include this .h-file and implement
the Adapter class in the following way:
#define Adapter Adaptee
#define my_method_1 Method1
#define my_method_2 Method2
If we build our Adapter and Target classes into a library, everything
goes fine. There are no compile or link errors.
Now we use our self-created library in an application, but then we got
linking errors to tell us that we have: "unresolved external symbols"
on the methods that are part of the Adapter classes. Our application
looks like this (simplified example):
int main(int argc, char *argv[])
{
int Result;
Adapter MyAdapter;
Target *pMyTarget = &MyAdapter;
Result = pMyTarget->my_method_1(0);
Result = pMyTarget->my_method_2();
return Result;
}
So my question is now. Can someone explain me what we are doing wrong
and how we can solve these linking errors?
Thanks,
Maurice