Hi all!
I'm new to this forum and I would say hello to everyone! Sorry for my english 'cause I'm Italian and something could has mistakes or errors.
I generally code in Java and I need to write something in C++ (I had previous experience but not too deep), that is a simple class that acts as a wrapper for another library. This library has a method addTerm() that adds a term to the object tree. Because each one can use a base type of their own I used templates and I also wrote a specialization of it to do some tests.
Anyway here is the base class/template
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
template <typename T>
class ITerm
{
public:
ITerm(T value) : val(value)
{
}
virtual ~ITerm() {};
inline int getVarNum() {
return size;
}
inline void setValue(T value) {
val = value;
}
inline T getValue() {
return val;
}
public:
virtual bool getIthVar(int idx) = 0;
private:
static const size_t size = sizeof(T)*8;
T val;
};
|
as you can see each one would use the type of their own and need only to supply the implemetation of the pure virtual function getIthVar. So I create a concrete implementation, here it is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
#include "iterm.h"
class UIntVar :
public ITerm<unsigned int>
{
public:
// class constructor
UIntVar(unsigned int value) : ITerm<unsigned int>(value) {
}
// class destructor
~UIntVar() {
}
bool getIthVar(int idx) {
return (getValue() & (1<<idx)) ? true : false;
}
};
|
I used unsigned integer as type but someone could use strings and access each char in the getIthVar and test if is "1" or "0" and return true of false.
I use this class in the main function like this:
1 2 3 4 5 6 7 8 9 10
|
// The library
BddWrapper wrap;
UIntVar var(0);
for(int i=0;i<10;i++)
{
var.setValue(i);
wrap.addTerm(var); // <-- here comes the error
}
|
The
BddWrapper
is defined as:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class BddWrapper
{
public:
BddWrapper();
BddWrapper(int varNum);
~BddWrapper();
template <typename T> bool addTerm(ITerm<T>& term);
private:
int varNum;
DdManager* manager;
DdNode* bdd;
};
|
Everyhing compiles fine (Visual Studio 2010) but honestly I don't know if the definition of member function
|
template <typename T> bool addTerm(ITerm<T>& term);
|
is right or not. I want to have the base templated class as argument type so I can pass to it any kind of concrete implemetation I want but it fails to link with this message:
error LNK2019: unresolved external symbol "public: bool __thiscall BddWrapper::addTerm<unsigned int>(class ITerm<unsigned int> &)" (??$addTerm@I@BddWrapper@@QAE_NAAV?$ITerm@I@@@Z) referenced in function _wmain
|
Everything compiles fine if I comment the line pointed in the main function.
Sorry if I was so long but hope I gave everything to find a solution.
I don't know if this has a
design error more than
coding one.
Moreover if anyone has suggestion, code tips or anything is a good programming practice it would be very appreciated!! (I haven't code in C++ for years!)
If you need more infos, don't hesitate to ask!
Thank you so much!!
Bye!