I get a linker error by creating this code:
File Exclude.h
class IsExclude
{
public:
template<typename T>
bool operator()(const T* par);
virtual ~IsExclude() = 0;
};
IsExclude::~IsExclude() {}
class IsExcludeA : public IsExclude
{
public:
IsExcludeA(std::string toCompare) : toCompare_(toCompare) {}
template<typename T>
bool operator()(const T* par)
{
return strcmp(par->Something, toCompare_.c_str() ) ? false : true ;
}
~IsExcludeA() {}
private:
std::string toCompare_;
};
In the same file:
template<typename T,typename P>
bool isExclude( const T& cont, const P* toCheck )
{
typename T::const_iterator pos;
typename T::const_iterator end(cont.end());
bool ret(false);
for (pos = cont.begin(); pos != end; ++pos)
{
if ( (*pos)->operator()(toCheck) == true )
{
ret = true;
pos = end;
}
}
return ret;
}
The cpp file in which I am using the previous call looks like this:
std::vector<IsExclude* > exVector;
exVector.push_back( new IsExcludeA(std::string("A")) );
exVector.push_back( new IsExcludeA(std::string("B")) );
if (isExclude(exVector,asset) == false)
{
}
The code compiles fine, but I got an error from the linker: Undefined first link character in bool IsExclude :: operator () (const __type_0 *) MyFile.o
Do you have any hints or suggestions?
PS I know that I need to clear the vector to avoid a memory leak. I can not use boost :: shared_ptr with my compiler. Sigh!
source
share