Hi, I'm trying to create a settings registry for a project I'm working on, and I've come into a problem. First, my code:
CSettingManager header
Code:
#ifndef __CSETTINGMANAGER
#define __CSETTINGMANAGER
// Include headers
#include <sstream>
#include <map>
#include <string>
#include "CSingleton.h"
// Setting manager class
class CSettingManager : public CSingleton<CSettingManager>
{
public:
CSettingManager();
~CSettingManager();
template <class T> bool addSetting(std::string name, T value);
template <class T> bool editSetting(std::string name, T value);
template <class T> bool getSetting(std::string name, T* outVar);
bool isSetting(std::string name);
bool loadSetting(std::string name);
bool saveSettings(std::string name);
void resetSettings();
private:
std::map<std::string, std::stringstream> Registry;
};
#endif //__CSETTINGMANAGER
As you can see, I have some templated functions that I can use to add any type of data to my setting registry. Here's the implementation of these functions.
Code:
// Add setting
// Adds a setting to the setting registry
template <class T>
bool CSettingManager::addSetting(std::string name, T value)
{
// Check to see if the setting is already in the registry
if (Registry.find(name) == Registry.end())
{
// Create a stringstream with the value in it and add it to the registry
std::stringstream RegValue;
RegValue << value;
Registry[name] = RegValue;
return true;
}
return false;
}
// Edit Setting
// Changes a value in the settings registry
template <class T>
bool CSettingManager::editSetting(std::string name, T value)
{
// Check to see if the setting is in the registry
if (Registry.find(name) != Registry.end())
{
std::stringstream RegValue;
RegValue << value;
Registry[name] = RegValue;
return true;
}
return false;
}
// Get Setting
// Returns a setting in the registry
template <class T>
bool CSettingManager::getSetting(std::string name, T* outVar)
{
// Check to see if the setting is in the registry
if (Registry.find(name) == Registry.end())
{
return false;
}
// Convert the stringstream in the registry to the native data type
Registry[name] >> *outVar;
return true;
}
I don't get any other errors other than the following when I try to add a setting.
Code:
undefined reference to `bool CSettingManager::addSetting<int>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)'
My main function looks like this:
Code:
int main()
{
CSettingManager* Manager = CSettingManager::getInstancePtr();
Manager->addSetting(string("Test"), 16);
Manager->drop();
}
Is what I'm doing possible, having templated member function in a non-templated class? If anyone can help me out, I'd really appreciate it.