I have a code as below and I don't understand why exactly compiler can't infer the constructor to be used when instance of D class is created. I have deleted both copy and move constructor so the only alternative would be to use A(Base&)
Is there are a way to tell compiler to use A(Base&) constructor, besides casting *this to Base&.
class Base {};
class A
{
private:
Base& m_b;
public:
A(Base& b) :m_b(b) {}
A(const A&) = delete;
A(A&&) = delete;
};
class D : public Base, public A
{
public:
D():A(*this){}
};
int main()
{
D();
}
The error I'm getting is as follows:
main.cpp: In constructor 'D::D()':
main.cpp:17:16: error: call of overloaded 'A(D&)' is ambiguous
D():A(*this){}
^
main.cpp:10:5: note: candidate: A::A(const A&) <deleted>
A(const A&) = delete;
^
main.cpp:9:5: note: candidate: A::A(Base&)
A(Base& b) :m_b(b) {}