A function with an argument does not compile with VC ++ by default, but does with g ++ and clang

I searched this site and cannot find a solution to my problem. I have reduced my sample code to the extent that I think I can, while preserving the corresponding error. I have the following two files left:

test.hpp

namespace models { template<typename FloatingPoint> class ellipsoid { public: explicit ellipsoid(FloatingPoint = 6378137.0); private: FloatingPoint a_; }; template<typename FloatingPoint> ellipsoid<FloatingPoint>::ellipsoid(FloatingPoint a) : a_(a) {} } // End namespace models // Function declaration template<typename FloatingPoint> FloatingPoint compute(FloatingPoint, const models::ellipsoid<FloatingPoint>& = models::ellipsoid<FloatingPoint>()); // Function definition template<typename FloatingPoint> FloatingPoint compute(FloatingPoint x, const models::ellipsoid<FloatingPoint>& model) { return 3.14; } 

test.cpp

 #include "test.hpp" int main() { compute(10.0); return 0; } 

When I compile the above code using VC ++ 2017, I get the following error:

 error C2512: 'models::ellipsoid<FloatingPoint>': no appropriate default constructor available note: No constructor could take the source type, or constructor overload resolution was ambiguous 

Both clang and g ++ compile this without any problems. Also, if I remove the ellipsoid class from the models namespace and delete the calls of models:: in the compute function, it then compiles using VC ++. Is this a bug in the VC ++ compiler, or do I have a bug in my code?

+5
source share

Source: https://habr.com/ru/post/1268061/


All Articles