Coversion operator template specialisation
The following won't compile. If I comment out the conversion operator specialisation it compiles and runs without any problem. As far as I can see I have followed the normal syntax for template function specialisation. Presumably the rules for conversion operators are different. Can anybody point me in the right direction? Thanks.
Code:
#include <iostream>
using namespace std;
template <class T> class I1
{
public:
T i, j;
I1(T a = 0, T b = 0): i(a), j(b){}
~I1(){}
template <class U> operator I1<U>()
{
return I1 <U> (U(i), U(j));
}
//problem with the following specialisation://
template <> operator I1<char>()
{
cout << "char specialisation" << endl;
return I1 <char> (char(i), char(j));
}
};
int main()
{
I1 <int> var2(97, 99);
cout << var2.i << ", " << var2.j << endl;
I1 <char> var3(var2);
cout << var3.i << ", " << var3.j << endl;
return 0;
}