|
-
May 12th, 2001, 11:58 AM
#1
Class Accessor Methods...
Is there a way to access a private member variable... so that to the user of the class it seems just to be a public const... but in actually fact its just a private member...
For example...
class X { // this class definition doesnt compile... just
private: // the best way to see what i am talkin about
int y;
public:
int y() { return this->y; }
};
X z;
cout << z.y; // this would display the contents of X::y.
z.y = 4; // this would be an error.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|