可能重复:
无法调用基类保护函数?
我不理解以下内容,当Derived继承自Base它时,它可以访问可以通过派生函数访问的受保护成员.但是,如果Base类试图从Derived类(它本身允许访问Base)访问自己的成员,它不能访问,为什么?
class Base {
protected:
int x;
};
class Derived : Base {
public:
void foo(Base* b);
};
void Derived::foo(Base* b) {
b->x = 2; // cannot access protected member,
// though Derived inherits from Base, why?
}
Run Code Online (Sandbox Code Playgroud) 从4.1/2
由左值表示的对象中包含的值是右值结果.当在sizeof(5.3.3)的操作数内发生左值到右值转换时,不会访问引用对象中包含的值,因为该运算符不会计算其操作数.
出于好奇,我想知道,同样适用于if,for,while语句,即当评估语句的结果时,左值是否转换为rvalue?