Hi I have a strange question. consider the following example.
I understand that private variable can be accessed only by private or public member functions.
class MyClass
{
private:
int value;
public:
void assign(const MyClass & x) {
value = x.value;
}
...
};
But in the above example function assign takes a reference parameter of type MYclass. we can also access x.value in the assign function. How can this be possible?. because when we are accessing the "x" x is a outside class to assign function and Assign function should not be allowed to access the private variable of x. Right??
Private members can only be accessed by member functions of the same class.
Since *this and x are instances of MyClass, MyClass::assign() can freely access their members.
It's very important to understand the difference between class (or type) and instance.