【问题标题】:the c++ access permission in a class [duplicate]类中的c ++访问权限[重复]
【发布时间】:2016-02-15 10:51:33
【问题描述】:
#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 是私有的,所以我认为tmp 不能访问它。但是为什么这段代码可以编译成功呢?

【问题讨论】:

    标签: c++


    【解决方案1】:

    私有字段不仅适用于其他类的对象。但可用于同一类的对象。

    【讨论】:

      猜你喜欢
      • 2015-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-20
      • 2016-02-14
      • 1970-01-01
      • 2017-10-08
      相关资源
      最近更新 更多