This is a stripped down version of an error I'm getting in a different program, but this is simpler. The problem comes from if I try to set something that isn't an int in MyClass
#include <iostream>
using namespace std;
template <typename T>
class MyClass
{
private:
T data;
public:
void Set(T const &);
void Print();
};
template <typename T> void MyClass<T> ::Set(T const &d)
{
data = d;
}
template <typename T> void MyClass<T>::Print()
{
cout << data << endl;
}
int main()
{
MyClass<int> c;
c.Set("boo");
c.Print();
return 0;
}
Here is the compile results:
test.cpp: In function ‘int main()’:
test.cpp:31: error: invalid conversion from ‘const char*’ to ‘int’
test.cpp:31: error: initializing argument 1 of ‘void MyClass<T>::Set(T) [with T = int]’
Also I got the skeleton of this code from somewhere where they used vectors and iterators with none of the problems of this