这让我在过去的一个半小时内生气。我知道这是一件小事,但无法找到问题所在(事实上,这是一个下雨的星期五下午,当然,这没有帮助)。模板方法未定义的参考错误
我已经定义了下面的类,将举行从文件中读取配置参数,并让我从我的程序访问它们:
class VAConfig {
friend std::ostream& operator<<(std::ostream& lhs, const VAConfig& rhs);
private:
VAConfig();
static std::string configFilename;
static VAConfig* pConfigInstance;
static TiXmlDocument* pXmlDoc;
std::map<std::string, std::string> valueHash;
public:
static VAConfig* getInstance();
static void setConfigFileName(std::string& filename) { configFilename = filename; }
virtual ~VAConfig();
void readParameterSet(std::string parameterGroupName);
template<typename T> T readParameter(const std::string parameterName);
template<typename T> T convert(const std::string& value);
};
其中方法convert()
在VAConfig.cpp
被定义为
template <typename T>
T VAConfig::convert(const std::string& value)
{
T t;
std::istringstream iss(value, std::istringstream::in);
iss >> t;
return t;
}
所有很简单。但是,当我从我的主程序测试使用
int y = parameters->convert<int>("5");
我收到undefined reference to 'int VAConfig::convert<int>...'
编译错误。同上readParameter()
。
考察了很多模板,教程,但不需经过不知道这一点。有任何想法吗?
一个半小时并没有那么糟......它昨天杀了我3。 – 2012-08-16 16:24:09