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

后端 未结 5 1991
野的像风
野的像风 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:31

    What is probably happening is that the template instantiation is happening separately for class A and B, thus ending in two void f(int) functions.

    This does not happen in D since there the compiler knows about the void f(int) function as a specialization and therefore does not specialize T for int.

提交回复
热议问题