I am not an expert of C++ so please, forgive my question. I am trying to create a class with a member that could be of any value. Something like this:
class Input {
private:
string name;
AnyValue value;
}
where AnyValue may be: int, float, string. I came up with this:
.h
template <typename Value>
class Input {
private:
string name;
Value value;
public:
Input<Value>(string name);
}
.cpp
template <typename Value>
Input<Value>::Input(string name) {
this->name = name;
this->value = 0;
}
template <typename Value>
void Input<Value>::setValue(Value value) {
this->value = value;
}
template <typename Value>
Value Input<Value>::getValue(void) {
return value;
}
main is
int main(int argc, const char * argv[]) {
Input<int> i1 = Input<int>("i1");
}
Problem is that I get this error message from the linker:
Undefined symbols for architecture x86_64:
"Input<int>::Input(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
_main in main.o
but I cannot understand what I am missing.