Why is this call to member function ambiguous?

前端 未结 3 1341
野趣味
野趣味 2020-12-18 20:06

Consider this class:

class Base{
public:
    void func(double a) = delete;
    void func(int a) const {}
};

int main(){
    Base base;

    base.func(1);
           


        
3条回答
  •  渐次进展
    2020-12-18 20:45

    When a function is overloaded, the overload resolution takes place first. The program is ill-formed if the deleted function is the best match and is selected.

    Therefore, your program would produce the same error as the following, because there is an implicit conversion from int to double and the compiler does not know what function you intend to call:

    class Base{
    public:
        void func(double a) {}
        void func(int a) const {}
    };
    

提交回复
热议问题