stonny <zh************@gmail.comwrote:
Other's have answered your direct question. I want to go over your code
and point out some issues that might help you understand it better...
class Number
{
public:
Number(int num=0):private_number(num) {};
Calling the variable "another_number_class" is incorrect. It is an
object that is a Number, not an object of some other class. Make sure
you understand the distinction between object and class.
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;
};
This might be more comprehensible:
void compare( const Number& that ) const
{
if ( this->private_number == that->private_number )
cout << "the two objects have the same numbers!" << endl;
}
Note, both objects, "this" object and "that" object, are of the same
class.
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?