about the private data member

S

stonny

class Number
{
public:
Number(int num=0):private_number(num) {};

void compare(const Number & another_number_class) const
{
if(this->private_number == another_number_class.private_number)
std::cout<<"the two classes have the same numbers !"<<std::endl;
else
std::cout<<"the two classes have different numbers !"<<std::endl;
};

private:
int private_number;
};



In this class Number, the function "compare" can reach the private
data member of both current object and "the parameter object". Is this
because both objects belong to the same class?

stonny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top