C++ class conversion

01881c4a529e2521a02930f36af18423
0
WindScar 101 Jan 30, 2010 at 23:58

The code explain it:

templace <class T>
class V2d { public: T x,y; }

int main()
{
  V2d<int> i(3,3);
  V2d<double> d(V2d<double>(i));
}

How to make the statement “V2d<double>(i)” at the 7th line work (to convert a V2d<int> object in an V2d<double> object)?

1 Reply

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Jan 31, 2010 at 00:38
template <class T>
class V2d
{
public:
    T x, y;
    V2d(T x_, T y_): x(x_), y(y_) {}

    template <class U>
    V2d(const V2d<U> & v): x(v.x), y(v.y) {}
};