RE: [Dev-C++] C++ Question (the real one)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ya...> - 2001-04-21 21:31:06
|
Thanks a lot. That was what i had guessed... but had not seen it written explicitly at any book (that class member functions of an object can access private members of another instance of the same class). Ioannis * Ioannis Vranos * Programming pages: http://members.nbci.com/noicys * Alternative URL: http://run.to/noicys > -----Original Message----- > From: dev...@li... > [mailto:dev...@li...]On Behalf Of Bolek Vrany > Sent: Saturday, April 21, 2001 10:22 PM > To: dev...@li... > Subject: Re: [Dev-C++] C++ Question (the real one) > > > > Ioannis Vranos wrote: > > > > Ok i was stupid for my previous question. The answer is because it was > > a friend function. Here is the real question: > > > > #include <iostream> > > > > class Matrix > > { > > double m[4][4]; > > > > public: > > void test(Matrix s); > > }; > > > > > > void Matrix::test(Matrix s) > > { > > for (int i=0; i<4; i++) > > { > > std::cout<<std::endl; > > > > for(int j=0; j<4; j++) > > std:: cout<<s.m[i][j]<<std::endl; > > } > > } > > > > int main() > > { > > > > return 0; > > } > > > > The member function test() accesses the private data member of its > > argument directly. When is it allowed for functions to access directly > > the private members of their arguments except of those declared > > as friends? > > It is allowed for friends and member functions of the same class (class > A) only - but it is allowed regeradless of whether it accesses data > members of its own instance (*this) or another instance of the class. > You can also declare a whole class B as a friend. This will cause all > member functions of class B to be friends of class A. > > -- > ============================================================ > Ing. Boleslav Vrany > Stanice techniku DDM hl. m. Prahy > Pod Juliskou 2a > Praha 6 - Dejvice > 16000 > Czech Republic > > tel. (420 2) 243 10 240 > > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > http://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |