Inheritance of friendship and private nested class

I would like to inherit from a nested class that is in a private section of an outer class. Is it possible?

class A { friend class B; friend class C; private: class NiceNestedClass { }; }; class C { void a() { A::NiceNestedClass works; } }; class B : A::NiceNestedClass{ }; 

Activating NiceNestedClass is not a problem. But g ++ does not allow me to inherit it. Is there a workaround?

 g++ -std=c++11 ac -oa ac:5:11: error: 'class A::NiceNestedClass' is private class NiceNestedClass { ^ ac:15:14: error: within this context class B : A::NiceNestedClass{ 

g ++ 4.8.4, std = C ++ 11

+5
source share
2 answers

This is a known gcc bug reported in 2013

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59482

Your code is correct and should compile with newer versions of gcc (fixed on gcc4.9 and later). On my side (gcc5.3) it works fine.

+5
source

It could be a mistake. Using gcc.godbolt.org and running

 #include <iostream> class A { friend class B; friend class C; private: class NiceNestedClass { }; }; class C { void a() { A::NiceNestedClass works; } }; class B : A::NiceNestedClass{ }; int main(){ } 

Works with every version of clang, ICC and gcc 4.9.2 or higher. It does not work with any gcc 4.8.x or lower.

+3
source

Source: https://habr.com/ru/post/1241626/


All Articles