B
bluekite2000
Here is the compilable code, along w/ the error
#include<iostream>
#include<complex>
typedef std::complex<float> ComplexSingle;
using namespace std;
template<typename T> class X
{
private:
T number;
public:
X(T value)
{
number=value;
}
template<typename Other> X(Other Y)
{
assign(Y);
}
template<typename Other> void assign(Other Y);
T return_number()
{
return number;
}
};
template<typename T>
template<typename Other> void X<T>::assign( Other Y)
{
number=Y.return_number();
}
template<> template<typename ComplexSingle> void
X<float>::assign(ComplexSingle Y)
{
number=norm(Y.return_number());
}
int main (void)
{
//this works fine
ComplexSingle a(2,3);
X<ComplexSingle> A(a);
X<float> B(A);
//error
//In member function `void X<T>::assign(Other) [with Other =
//X<double>, T = float]':
//ex1.cc:16: instantiated from `X<T>::X(Other) [with Other =
// X<double>, T = float]'
//ex1.cc:45: instantiated from here
//ex1.cc:35: error: no matching function for call to `norm(double)'
X<double> C(3.3);
X<float> D(C);
return 0;
}
#include<iostream>
#include<complex>
typedef std::complex<float> ComplexSingle;
using namespace std;
template<typename T> class X
{
private:
T number;
public:
X(T value)
{
number=value;
}
template<typename Other> X(Other Y)
{
assign(Y);
}
template<typename Other> void assign(Other Y);
T return_number()
{
return number;
}
};
template<typename T>
template<typename Other> void X<T>::assign( Other Y)
{
number=Y.return_number();
}
template<> template<typename ComplexSingle> void
X<float>::assign(ComplexSingle Y)
{
number=norm(Y.return_number());
}
int main (void)
{
//this works fine
ComplexSingle a(2,3);
X<ComplexSingle> A(a);
X<float> B(A);
//error
//In member function `void X<T>::assign(Other) [with Other =
//X<double>, T = float]':
//ex1.cc:16: instantiated from `X<T>::X(Other) [with Other =
// X<double>, T = float]'
//ex1.cc:45: instantiated from here
//ex1.cc:35: error: no matching function for call to `norm(double)'
X<double> C(3.3);
X<float> D(C);
return 0;
}