谁帮我做一个c++判断题?

来源:百度知道 编辑:UC知道 时间:2024/06/17 14:57:55
设a是类A的一个保护变量成员,t是类A的一个对象,那么t.a这个表达式可以访问。
是对的吗,为什么?

不可以的,你可以在类内部访问。你可以自己编个像这样的小程序,看他编译能不能过.
class A
{
protected:
int a;
};

int main()
{
A t;
t.a;
return 0;
}
这个过不了,提示
error C2248: 'a' : cannot access protected member declared in class 'A'。大概能看明白吧!

错误。只有public成员才可以访问。

SORRY SORRY...
不能,上面的是对的~