fork download
  1. template<typename T>
  2. class Vector2D
  3. {
  4. public:
  5. explicit Vector2D(): x(0), y(0)
  6. {
  7. }
  8.  
  9. explicit Vector2D(const T x_, const T y_): x(x_), y(y_)
  10. {
  11. }
  12.  
  13. template<typename U>
  14. Vector2D(const Vector2D<U>& v): x(T(v.x)), y(T(v.y))
  15. {
  16. }
  17.  
  18. union
  19. {
  20. struct { T x, y; };
  21. struct { T i, j; };
  22. };
  23. };
  24.  
  25. int main(int argc, char* argv[])
  26. {
  27. Vector2D<int> v1(1, 2);
  28. Vector2D<float> v2(v1);
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0s 2892KB
stdin
Standard input is empty
stdout
Standard output is empty