//In file1.hpp
class A
{
protected:
class B
{
public:
B(int a, int b)
: c(a),
d(b) {}
private:
int c;
int d;
};
};
// In file2.hpp
Class C
{
public:
class D : public A::B --------- This line shows the error that "no matching function for call to B"
{
public:
D() {};
virtual ~D() {};
//something
}
class E : public D
{
E() {};
virtual ~E() {};
}
}
I am getting an error while inheriting the A::B class in D class. In my main.cpp, I instantiate the D class directly. I am assuming that when D class is instantiated, class A::B gets instantiated automatically.
The error is because I am instantiating D class but not giving the parameters for the instantiation of A::B class.
Right now in main.cpp file, I just write C::D obj;
My question is, how do I instantiate from main.cpp, the class D and also give parameters for class A::B? I do not want to pass as parameters while instantiating class D. Is there a way to create a method? In short I can create a method in main.cpp to pass parameters for class A::B but not pass parameters like C::D obj(hi, hey)