|
| Total Answers and Comments: 4 |
Last Update: June 12, 2009 |
|
| | |
|
Submitted by: Arvind
Its the main feature of a class that private member data of a class can be accessed only by the class' member functions. But there is an exception , A class can allow non-member functions and other classes to access its own private data, by making them as friends. class Test { private: int a;
public: void xyz( ); friend void display(Test); //Friend of the class 'Test' , display() can access the //private data members of the class }
void display(Test x) { cout << x.a;// Class private data can be accessed. }
Above answer was rated as good by the following members: geeker2008, ozkan, the_ankit1987 | Go To Top
|