It drove me crazy in the last hour and a half. I know this little thing, but I can’t find what is wrong (the fact that it does not help on a rainy day on Friday, of course).
I defined the following class, which will contain configuration parameters read from a file, and will give me access to them from my program:
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 ); };
where the convert() method is defined in VAConfig.cpp as
template <typename T> T VAConfig::convert( const std::string& value ) { T t; std::istringstream iss( value, std::istringstream::in ); iss >> t; return t; }
Everything is pretty simple. But when I test my main program using
int y = parameters->convert<int>("5");
I get a compilation error undefined reference to 'int VAConfig::convert<int>...' . Same for readParameter() .
Looked at a lot of patterns, but coul didn't get it. Any ideas?
c ++ compilation linker templates
recipriversexclusion Jul 10 '09 at 19:13 2009-07-10 19:13
source share