相关疑难解决方法(0)

为什么有注入的类名?

最近,我看到了一个奇怪的C++特性:注入类名.

class X { };
X x1;
class X::X x2; // class X::X is equal to X
class X::X::X x3; // ...and so on...
Run Code Online (Sandbox Code Playgroud)

但我无法弄清楚为什么这个功能是必要的.有没有需要此功能的练习?

我听说旧C++中不存在这个功能.然后,什么时候介绍?C++ 03?C++ 11?

c++

142
推荐指数
1
解决办法
6321
查看次数

C++语法"A :: B:A {};"是什么意思

C++语法struct A::B:A {};是什么意思?C++标准中描述的名称定义(或访问)在哪里?

#include <iostream>

struct B;

struct A {
    struct B;
};

struct A::B:A {
};

int main() {
    A::B::A::B b;
    std::cout<<"Sizeof A::B::A::B is " << sizeof(A::B::A::B)<<std::endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ syntax struct scope-resolution

64
推荐指数
2
解决办法
8090
查看次数

标签 统计

c++ ×2

scope-resolution ×1

struct ×1

syntax ×1