I am using the following classes declaration:
class A {
public:
A(int, float);
A(const A&);
};
class B {
public:
B(A&);
protected:
A a;
};
I also set up the following definition for B:
B::B(A &a) {
this->a = a;
}
The problem is I have an error on the definition of my Bconstructor, telling me that there is No matching function for call to A::A().
Why does my B constructor tries to create a new A?
If the previous step is needed, why doesn’t it call the copy constructor using the reference?
I assume your
Bhas anAthat needs to be constructed. In your current constructor, your not explicitely specifying anAconstructor to use. Therefore it tries the default constructor ofAwhich does not exist:Maybe you meant to construct B’s A with the reference?