Ambiguous when two superclasses have a member function with the same name, but different signatures

后端 未结 5 1990
野的像风
野的像风 2021-01-31 03:52
struct A {
    void f(int x) {}
};

struct B {
    template void f(T x) {}
};

struct C : public A, public B {};

struct D {
    void f(int x){}
    te         


        
5条回答
  •  后悔当初
    2021-01-31 04:32

    A compiler doesn't know which method to call from the C class because templated method will be transormed in void f(int) in case of int type so you have two methods with the same name and same arguments but members of different parent classes.

    template void f(T x) {} 
    

    or

    void f(int)
    

    try this:

    c.B::f(3);
    

    or this for the A class:

    c.A::f(3);
    

提交回复
热议问题