I was somehow surprised that the following code compiles and runs (vc2012 & gcc4.7.2)
class Foo {
struct Bar { int i; };
public:
Bar Baz() { retu
This question has already been answered very well by both chill and R. Martinho Fernandes.
I just couldn't pass up the opportunity to answer a question with a Harry Potter analogy:
class Wizard
{
private:
class LordVoldemort
{
void avada_kedavra()
{
// scary stuff
}
};
public:
using HeWhoMustNotBeNamed = LordVoldemort;
friend class Harry;
};
class Harry : Wizard
{
public:
Wizard::LordVoldemort;
};
int main()
{
Wizard::HeWhoMustNotBeNamed tom; // OK
// Wizard::LordVoldemort not_allowed; // Not OK
Harry::LordVoldemort im_not_scared; // OK
return 0;
}
https://ideone.com/I5q7gw
Thanks to Quentin for reminding me of the Harry loophole.