struct A {
protected:
int y;
public:
int z;
};
struct F : A {
public:
using A::y;
private:
using A::z;
};
int main() {
F obj_F;
obj_F.y = 9;
obj_F.z = 10;
}
Source: http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=/com.ibm.vacpp7a.doc/language/ref/clrc14cplr135.htm
In the above code obj_F.z = 10; – is allowed.
Explanation: The access of member z is still public. The private using declaration using A::z has no effect on the access of z.
Can someone tell me, if z, which is declared as private, is accessible outside, then what is the meaning of that private? What does it do?
Thanks
-Saiyasodharan
The code is valid according to the Standard – see this Standard rule, which I did not have in mind when I answered before
This entirely applies to your code, and thus the access is valid… It appears the main purpose of this rule is for allowing friend declarations of the base to apply to inherited members, but it also applies to this case.
(Disregard the parts of this that say the code is invalid – It’s valid as explained above. This part is an old version of my answer, kept here to serve as background information)
No, this code is invalid. That’s why the equivalent “access-declarations” are called that way (these are deprecated though)
These are called “access-declarations” precisely because they can change the access… In your example the naming class is
Fandzas a member ofFis private because the using-declaration did change the access level of the namez.