class B {
int x;
int y;
};
class A {
friend class Other;
friend class A;
int a;
B* b;
public:
A(){ b = new B();}
};
struct Other {
A a;
void foo() {
std::cout << a.b->x; // error
}
};
int main() {
Other oth;
oth.foo();
}
belirtilen satır başarısız: Diğer sınıf üyesine sınıf üyesinden bahsederken neden dostluk çalışmıyor
t.cpp:22:19: error: 'x' is a private member of 'B'
std::cout << a.b->x;
^
t.cpp:7:5: note: implicitly declared private here
int x;
?
Eh, 'Diğer' 'B sınıfı' bir' '' '' '' '' '' '' '' '' '' '' '' '' '• '' özel 'B :: x' erişilemez. –
Bir cevap sizin için işe yaradıysa, [kabul edildiği gibi işaretleyin] (http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work). Eğer kimse yapmadıysa, açıklama veya düzeltme talep eden bir yorum ekleyin (gerekirse). – Nacho