Reputation: 19
hello guys can anyone help me :
#include <iostream>
using namespace std;
class A
{
private:
int a;
protected:
int b;
void set_value(int y, int u, int i)
{
a = y;
b = u;
c = i;
}
public:
int c;
};
class B : private A
{
public:
A::set_value; //Compilation Error !
A::b; //Compilation Error !
};
int main()
{
B b;
b.set_value(1,1,1); //Compilation Error !
cout<<b.b; //Compilation Error !
}
How i Could Make protected member in super class can accessed directly (with out get() or set()) in main function using subclass
Upvotes: 0
Views: 62
Reputation: 19
first when i use Clang++ it shows me error when i compile, When I use G++ compiler version 9.3.0 it works with me correctly Thanks Guys.
Upvotes: 0
Reputation: 4655
Quoting from cppreference (emphasis mine)
Using-declaration introduces a member of a base class into the derived class definition, such as to expose a protected member of base as public member of derived.
So the solution is to write the class as follows:
class B : private A
{
public:
using A::set_value;
using A::b;
};
Full example here.
It seems the access declarations were deprecated in C++98 and finally removed in C++11.
Upvotes: 2