0
#include <iostream>

class Base
{
private:
    int num;
public:
    Base(int tmp = 0) : num(tmp) {}
    const Base& operator=(const Base& tmp)
    {
        num = tmp.num;//why tmp can use num?
        return *this;
    } 
};
int main()
{
    return 0;
}

details: num is private, so I think tmp can't access it.But why this code can be compiled successfully?

1 Answers1

0

Private fields is not available only for objects of another classes. But available for objects of same class.

oklas
  • 7,935
  • 2
  • 26
  • 42