我正在构建这段代码时遇到链接器错误:
排除.h文件
在同一个文件中:
代码编译完成,但链接器出现错误: 未定义的符号 在文件中 bool IsExclude::operator()(const __type_0*) MyFile.o
你有什么提示或建议吗?
P.S. 我知道我需要清理向量以避免内存泄漏。我的编译器不能使用boost::shared_ptr。叹息!
排除.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_;
};
在同一个文件中:
/*
* loop over a container of function objects
* if at least one of them return true the function
* return true, otherwise false
* The function was designed to evaluate a set of
* exclusion rule put in "and" condition.
*/
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;
}
我使用前面的调用的cpp文件如下:
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)
{
// Blah
}
代码编译完成,但链接器出现错误: 未定义的符号 在文件中 bool IsExclude::operator()(const __type_0*) MyFile.o
你有什么提示或建议吗?
P.S. 我知道我需要清理向量以避免内存泄漏。我的编译器不能使用boost::shared_ptr。叹息!
return strcmp(par->Something, toCompare_.c_str() ) ? false : true ;
改写为return par->Something == toCompare;
。 - user102008