Jump to content


C++ class conversion


1 reply to this topic

#1 WindScar

    New Member

  • Members
  • PipPip
  • 21 posts

Posted 30 January 2010 - 11:58 PM

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)?

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5344 posts
  • LocationSanta Clara, CA

Posted 31 January 2010 - 12:38 AM

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) {}
};

reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users