Floating point and integer ambiguity

I have a function (and constructor) that should be able to accept integer and floating point values. Actually, I want him to accept int64_tor long double, therefore, I want

class Foo {
    public:
    Foo(int64_t value=0);
    Foo(long double value);
};

However, if I do this and try Foo f = 1;, the compiler complains that the conversion from intto is Fooambiguous. Well, but if I changed the first constructor to, then there is no such ambiguity. Can someone explain to me why this is so.

+3
source share
1 answer

1 - int. , int to int64_t vs int long double. , , . , Foo (int). , (int64_t) 1.

+8

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


All Articles