Проблема с компиляцией кода ниже под VS2005. В VS 2008 и под gcc народ собирает.
Там где собирается это нестандартазированная фича?
class A {
A() {}
friend class B;
};
class B {
public:
class C {
C() {
A a; //тут в VS 2005 error: cannot access private member declared in class 'A'
}
};
B() {
A a; //ok
}
};
Здравствуйте, ST1, Вы писали:
ST1>Проблема с компиляцией кода ниже под VS2005. В VS 2008 и под gcc народ собирает.
ST1>Там где собирается это нестандартазированная фича?
Это стандартизованная фича, но в стандарте 0x )
Вот выдержка из 2003:
11.4/2
...
However, the declarations of members of classes nested within the friend
class cannot access the names of private and protected members from the class granting friendship.
...
а вот их 0х
Declaring a class to be a friend implies that the names of private and protected members from the class granting friendship
can be accessed in the base-specifiers and member declarations of the befriended class.
[ Example:
class A {
class B { };
friend class X;
};
struct X : A::B { // OK: A::B accessible to friend
A::B mx; // OK: A::B accessible to member of friend
class Y {
A::B my; // OK: A::B accessible to nested member of friend
};
};
—end example ]
B>а вот их 0х
B>B>Declaring a class to be a friend implies that the names of private and protected members from the class granting friendship
B>can be accessed in the base-specifiers and member declarations of the befriended class.
B>[ Example:
B>
B>class A {
B> class B { };
B> friend class X;
B>};
B>struct X : A::B { // OK: A::B accessible to friend
B> A::B mx; // OK: A::B accessible to member of friend
B> class Y {
B> A::B my; // OK: A::B accessible to nested member of friend
B> };
B>};
B>
B>—end example ]
забавно, что комо-онлайн вообще уже не пойми чему соответствует — спокойно компилит примеры из стандарта, которые должны приводить к ошибкам