Protecting object data from member functions

Protecting object data from member functions

Post by Peter Nea » Fri, 12 Dec 2003 01:31:58


Hi,

Consider the following (contrived!) class:

class myclass
{
public:
void display() const;
void double_X(); // x = x^2
void double_Y(); // y = y^2

private:
int X;
int Y;
};

I can protect X and Y from mutation in the display function by defining it
as const.

How would I protect Y from mutation whilst inside the double_X function and
likewise X whilst inside double_Y?

Any help gratefully received!

Pete.
 
 
 

Protecting object data from member functions

Post by Karl Heinz » Fri, 12 Dec 2003 01:56:24


You can't.
In this case it is an all or nothing situation.


--
Karl Heinz Buchegger
XXXX@XXXXX.COM