fork download
  1. #include <type_traits>
  2.  
  3. namespace foo {
  4. struct Vector {
  5. double x, y, z;
  6.  
  7. Vector(double x, double y, double z) :
  8. x{x}, y{y}, z{z}
  9. {}
  10.  
  11. template<class T>
  12. Vector(const T& foreign) :
  13. x{foreign.x}, y{foreign.y}, z{foreign.z}
  14. {}
  15.  
  16.  
  17. template<class T>
  18. operator T() const
  19. {
  20. return T{x, y, z};
  21. }
  22. };
  23.  
  24.  
  25. Vector makeAVector()
  26. {
  27. return {1, 2, 3};
  28. }
  29. }
  30.  
  31.  
  32. namespace bar {
  33.  
  34. struct Vector3 {
  35. using Scalar = double;
  36.  
  37. Scalar x, y, z;
  38.  
  39. Vector3(Scalar x, Scalar y, Scalar z) :
  40. x{x}, y{y}, z{z}
  41. {}
  42.  
  43. Vector3(const Vector3& other) :
  44. x{other.x}, y{other.y}, z{other.z}
  45. {}
  46.  
  47. Vector3(const Scalar *ptr) :
  48. x{ptr[0]}, y{ptr[1]}, z{ptr[2]}
  49. {}
  50.  
  51. };
  52.  
  53. void doSomething(const Vector3& v, double* x)
  54. {}
  55.  
  56. void doSomething(const Vector3& v, const Vector3& x)
  57. {}
  58.  
  59. }
  60.  
  61.  
  62. int main()
  63. {
  64. bar::Vector3 a{2, 3, 4};
  65.  
  66. bar::doSomething( a, foo::makeAVector() );
  67. }
  68.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:66:45: error: call of overloaded ‘doSomething(bar::Vector3&, foo::Vector)’ is ambiguous
     bar::doSomething( a, foo::makeAVector() );
                                             ^
prog.cpp:66:45: note: candidates are:
prog.cpp:53:10: note: void bar::doSomething(const bar::Vector3&, double*)
     void doSomething(const Vector3& v, double* x)
          ^
prog.cpp:56:10: note: void bar::doSomething(const bar::Vector3&, const bar::Vector3&)
     void doSomething(const Vector3& v, const Vector3&  x)
          ^
stdout
Standard output is empty