के लिए अनिर्धारित संदर्भ त्रुटि यह पिछले डेढ़ घंटे से मुझे पागल कर रही है। मुझे पता है कि यह एक छोटी सी बात है लेकिन क्या गलत नहीं है (तथ्य यह है कि शुक्रवार दोपहर बारिश होती है, ज़ाहिर है, मदद नहीं करता है)।टेम्पलेट विधि
मैं निम्नलिखित वर्ग है कि एक फ़ाइल से पढ़ने कॉन्फ़िगरेशन पैरामीटर का आयोजन करेगा और मुझे उन्हें अपने कार्यक्रम से भी एक्सेस करने देगा परिभाषित किया है:
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()
template <typename T>
T VAConfig::convert(const std::string& value)
{
T t;
std::istringstream iss(value, std::istringstream::in);
iss >> t;
return t;
}
रूप
VAConfig.cpp
में परिभाषित किया गया है
सभी काफी सरल। लेकिन जब मैं अपने मुख्य
int y = parameters->convert<int>("5");
का उपयोग कर कार्यक्रम से परीक्षण मैं एक undefined reference to 'int VAConfig::convert<int>...'
संकलन त्रुटि मिलती है। readParameter()
के लिए डितो।
बहुत सारे टेम्पलेट ट्यूटोरियल देखे लेकिन इसे समझ में नहीं आया। कोई विचार?
डेढ़ घंटे इतना बुरा नहीं है ... उसने मुझे कल 3 के लिए मार डाला। –