When B b(0);
is called I am expecting it to call the default constructor to initialize protected data member data_ but it is showing error.
error: no matching function for call to ‘B::B(int)’
candidate expects 0 arguments, 1 provided
Similar is the case for D d(1, 2);
.
no matching function for call to ‘D::D(int, int)’
candidate expects 0 arguments, 2 provided
#include <iostream>
using namespace std;
class B
{
protected: // Accessible to child
// Inaccessible to others
int data_;
public:
// ...
void Print()
{
cout << "B Object: ";
cout << data_ << endl;
}
};
class D : public B
{
int info_;
public:
// ...
void Print()
{
cout << "D Object: ";
cout << data_ << ", "; // Accessible
cout << info_ << endl;
}
};
int main()
{
B b(0);
D d(1, 2);
//b.data_ = 5; // Inaccessible to others
b.Print();
d.Print();
return 0;
}
What should I change to correct this?