nested classからは親のprivate空間にアクセスできるか。
C++Builder 2009でもエラーになりました。残念。
[BCC32 エラー] File1.cpp(25): E2247 'Hoge::func()' はアクセスできない
元ネタは、!Inner classes have no special access to the outer class in C++.
class Hoge {
public:
Hoge () : bar_(*this) {}
private:
class Bar {
public:
Bar(Hoge& hoge) : hoge_(hoge) {}
void func() {
hoge_.func();
}
Hoge& hoge_;
};
Bar bar_;
void func(){
cout << "func" << endl;
}
public:
Bar& Bar() { return bar_; }
};
int main()
{
Hoge hoge;
hoge.Bar().func();
return 0;
}