|
From: Ioannis V. <no...@ya...> - 2001-04-21 19:48:10
|
Guys & girls i need your help. :)
We have the following C++ code:
#include <iostream>
class Matrix
{
double m[4][4];
public:
friend Matrix operator+(const Matrix &, const Matrix &);
};
Matrix operator+(const Matrix &arg1, const Matrix &arg2)
{
Matrix sum;
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
sum.m[i][j]=arg1.m[i][j] + arg2.m[i][j];
}
return sum;
}
int main()
{
return 0;
}
It compiles ok. In the definition of operator+ we have the access of private
data members using the . notion directly. The code was taken from
Stroustrup's special edition. In that book i have seen the same access style
of private data members in all member functions of a class. What is the rule
here? Under what circumstances can we access directly private members of a
class?
I hope someone will help to figure it out.
Thanks in advance,
Ioannis
* Ioannis Vranos
* Programming pages: http://members.nbci.com/noicys
* Alternative URL: http://run.to/noicys
|