Let's consider the next code:
#include <iostream>
#include "mydemangled.hpp"
using namespace std;
struct A
{
private:
struct B {
int get() const { return 5; }
};
public:
B get() const { return B(); }
};
int main()
{
A a;
A::B b = a.get();
cout << demangled(b) << endl;
cout << b.get() << endl;
}
And the compiler (gcc 4.7.2) yells saying that A::B
is private. All right.
So, I change the code:
int main()
{
A a;
cout << demangled(a.get()) << endl;
cout << a.get().get() << endl;
}
and it doesn't yell:
$ ./a.out
A::B
5
Meaning, I can't to create instances of A::B
, but I can use it.
So, new change (the key of my question).
int main()
{
A a;
auto b = a.get();
cout << demangled(b) << endl;
cout << b.get() << endl;
}
And output:
$ ./a.out
A::B
5
What is the trouble here, being A::B
private (and thus its constructors, copy constructors and so on)?