Consider the following code:
class A {
class B {};
};
template <typename C>
class D : A::B {};
void f() {
D<int> d;
}
D<int>
inherits from A::B
which is a private nested class. I was expecting this to be an error, but GCC accepts this code. Is it a bug in GCC or am I missing something?
A nested class has access to all the private members of its enclosing class—both fields and methods. Therefore, a public or protected nested class inherited by a subclass has indirect access to all of the private members of the superclass.
Accessing the Private Members Write an inner class in it, return the private members from a method within the inner class, say, getValue(), and finally from another class (from which you want to access the private members) call the getValue() method of the inner class.
A nested class is a member of its enclosing class. Non-static nested classes (inner classes) have access to other members of the enclosing class, even if they are declared private.
A nested class is a class which is declared in another enclosing class. A nested class is a member and as such has the same access rights as any other member. The members of an enclosing class have no special access to members of a nested class; the usual access rules shall be obeyed.
I've found the answer. Since it's might be useful for others I am posting it here - this is GCC bug 47346.
Did you try to create non template derivering class?
Template class is not compiled if there is no object of that class. Try to create instance of this class or create non-template derived class - gcc will probably fail ;-)
Edit My bad - the object is created and it's not causing gcc error. Sorry for that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With