 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jens Auer Guest
|
Posted: Wed Sep 06, 2006 3:15 pm Post subject: Zugriffsrechte bei verschachtelten Klassen |
|
|
Hallo,
wie lauten die Regeln im C++-Standard fuer die Zugriffsrechte auf
private Attribute im Falle von verschachtelten Klassen? Im Internet habe
ich z.B. in einer Doku zu einem IBM-Compiler folgendes Beispiel gefunden:
class A {
int x;
class B { };
class C {
// 1
// The compiler cannot allow the following
// declaration because A::B is private:
B b;
int y;
void f(A* p, int i) {
// 2
// The compiler cannot allow the following
// statement because A: is private:
p->x = i;
}
};
void g(C* p) {
// The compiler cannot allow the following
// statement because C::y is private:
// int z = p->y;
}
};
Laut IBM sind die beien Zugriffe 1 und 2 nicht erlaubt, sowohl der gcc
(4.0.3) als auch Intels Compiler (9.1) erlauben den Zugriff. |
|
| Back to top |
|
 |
Björn Hendriks Guest
|
Posted: Thu Sep 07, 2006 2:29 am Post subject: Re: Zugriffsrechte bei verschachtelten Klassen |
|
|
Jens Auer wrote:
| Quote: | wie lauten die Regeln im C++-Standard fuer die Zugriffsrechte auf
private Attribute im Falle von verschachtelten Klassen? Im Internet habe
ich z.B. in einer Doku zu einem IBM-Compiler folgendes Beispiel gefunden:
class A {
int x;
class B { };
class C {
// 1
// The compiler cannot allow the following
// declaration because A::B is private:
B b;
int y;
void f(A* p, int i) {
// 2
// The compiler cannot allow the following
// statement because A: is private:
p->x = i;
}
};
void g(C* p) {
// The compiler cannot allow the following
// statement because C::y is private:
// int z = p->y;
}
};
Laut IBM sind die beien Zugriffe 1 und 2 nicht erlaubt, sowohl der gcc
(4.0.3) als auch Intels Compiler (9.1) erlauben den Zugriff.
|
Dieses Beispiel steht genau so (abgesehen von den Namen der Klassen und den
ausführlichen Kommentaren) im Standard (11.8.1), ist also standardkonform.
MfG
Björn |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|