M
Milan
I need some help on the following simple program:
//////////////////////////////////////////////
template <class T>
class A
{
public:
T x, y;
A(){x = y = 0;}
A(T x_, T y_):x(x_), y(y_){}
template <class X> A(const A<X> &a){x = a.x; y = a.y; cout << "A" << endl;}
};
class B: public A<int>
{
public:
B(){}
B(int x_, int y_): A<int>(x_, y_){}
template <class X> B(const A<X> &a): A<X>(a){cout << "B" << endl;}
};
class C: public A<double>
{
public:
C(){}
C(double x_, double y_): A<double>(x_, y_){}
template <class X> C(const A<X> &a): A<X>(a){cout << "C" << endl;}
};
int main(int argc, char* argv[])
{
B obj1;
C obj2 = B;
return 0;
}
//////////////////////////////////////////////
It fails to compile on the "C obj2 = B" line. Why?
Thanks for the help.
Regards,
Milan.
//////////////////////////////////////////////
template <class T>
class A
{
public:
T x, y;
A(){x = y = 0;}
A(T x_, T y_):x(x_), y(y_){}
template <class X> A(const A<X> &a){x = a.x; y = a.y; cout << "A" << endl;}
};
class B: public A<int>
{
public:
B(){}
B(int x_, int y_): A<int>(x_, y_){}
template <class X> B(const A<X> &a): A<X>(a){cout << "B" << endl;}
};
class C: public A<double>
{
public:
C(){}
C(double x_, double y_): A<double>(x_, y_){}
template <class X> C(const A<X> &a): A<X>(a){cout << "C" << endl;}
};
int main(int argc, char* argv[])
{
B obj1;
C obj2 = B;
return 0;
}
//////////////////////////////////////////////
It fails to compile on the "C obj2 = B" line. Why?
Thanks for the help.
Regards,
Milan.