This is driving me mad for the past 1.5 hrs, I know it's a small thing but cannot find what's wrong (the fact that it's a rainy Friday afternoon, of course, does not help).
I have defined the following class that will hold configuration parameters read from a file and will let me access 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 method convert()
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;
}
All quite simple. But when I test from my main program using
int y = parameters->convert<int>("5");
I get an "undefined reference to int VAConfig::convert<int>...
" compilation error. Ditto for readParameter()
.
Looked at a lot of template tutorials but coul not figure this out. Any ideas?
Thanks, C