在C++规范的语法中,类的成员定义为:
member-declaration:
decl-specifier-seq(optional) member-declarator-list(optional);
function-definition ;(optional)
::(optional) nested-name-specifier template(optional) unqualified-id ;//what is this?
using-declaration
template-declaration
...我能理解其中的四个。但是第三个定义了一个强制嵌套的名称说明符,后面跟着一个id。e.g
class {
X::Y::z;
}我不知道任何与此定义相匹配的C++语法。我错过了什么吗?
发布于 2014-05-23 16:58:02
答案可以在class.access.dcl部分找到。简而言之,这样的声明称为“访问声明”,其目的是更改继承成员的访问级别。
例如:
class A
{
protected:
int a;
int a1;
};
class B
{
public:
int b;
int b1;
};
class C : public A, private B
{
public:
A::a;
B::b;
}
int f()
{
C c;
c.a1; // access error: A::a1 is protected
c.b1; // access error: B is private base of A
c.a; // accessible because A::a is 'published' by C
c.b; // accessible because B::b is 'published' by C
}这种声明被using所取代,但为了兼容性的目的而保留。
https://stackoverflow.com/questions/23834139
复制相似问题