#include<iostream>
using namespace std;
class Base{
private:
int a;
protected:
Base(){};
virtual ~Base(){};
};
class Derived:private Base{
private:
int b;
public:
Derived(){};
~Derived(){};
void test(){
Base world;
};
};
int main(){
}
inherit.cc|7 col 3| error: ‘Base::Base()’ is protected
inherit.cc|17 col 9| error: within this context
inherit.cc|8 col 11| error: ‘virtual Base::~Base()’ is protected
inherit.cc|17 col 9| error: within this context
But why?
And why this is correct?
#include<iostream>
using namespace std;
class Base{
private:
int a;
protected:
Base(){};
virtual ~Base(){};
void test2(){};
};
class Derived:private Base{
private:
int b;
public:
Derived(){};
~Derived(){};
void test(){
test2();
};
};
int main(){
}