delorie.com/archives/browse.cgi | search |
Message-ID: | <3E739182.6E629D7A@bluewin.ch> |
Date: | Sat, 15 Mar 2003 21:48:02 +0100 |
From: | Simon Bachmann <simonbachmann AT bluewin DOT ch> |
X-Mailer: | Mozilla 4.7 [en] (X11; I; Linux 2.2.13 i586) |
X-Accept-Language: | en |
MIME-Version: | 1.0 |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | data access in nested classes |
NNTP-Posting-Host: | 213.3.167.100 |
X-Original-NNTP-Posting-Host: | 213.3.167.100 |
X-Trace: | news.bluewin.ch 1047761072 213.3.167.100 (15 Mar 2003 21:44:32 +0100) |
Organization: | Bluewin AG |
Lines: | 70 |
Complaints-To: | abuse AT bluewin DOT ch |
X-Original-NNTP-Posting-Host: | 127.0.0.1 |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
Hello! I've got a problem with gpp(version 3.1), I don't know if it's a problem of gpp intself or of the ported vesion. I've got gcc under linux too, and here the problem doesn't exist, but it's another version.... (2.7). That's the problem: wen I create two nested classes and try to access from the one to the other's private data, (without making it a friend) the compiler should give me an error message. Well, it doesn't! Here's an example: #include <iostream> using namespace std; class One { public: class Two; //this two lines should be necessary but they are not !! friend class Two; //commenting them and compiling I get no error messagges //compilatino under linux with this lines commented fails class Two { friend class One; //This line is necessary under both dos and linux public: void ini(); int val_one(One *); private: int t; }; void ini(); int val_two(Two *); private: int o; }; void One::ini() { o = 1; } void One::Two::ini() { t = 2; } int One::val_two(Two * p) { return p->t; } int One::Two::val_one(One * p) { return p->o; } main () { One o_1; One::Two o_2; o_1.ini(); o_2.ini(); cout << endl << "One::o = " << o_2.val_one( &o_1 ) << endl << "Two::t = " << o_1.val_two( &o_2) << endl << endl; }
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |