我以前从未见过它.我认为这是":: sample"的拼写错误,但是当我看到它实际编译时我很困惑.有人能帮我找到吗?我不认为这是一个goto
标签.
void f() {
class: sample {
// there were some members declared here
} x;
}
Run Code Online (Sandbox Code Playgroud)
Ale*_* C. 80
它是一个未命名的类,冒号意味着它私下继承sample
.看到它
class Foo : private sample
{
// ...
};
Foo x;
Run Code Online (Sandbox Code Playgroud)
Naw*_*waz 21
我认为这是定义一个源自的无名类sample
.并且x
是该未命名类的变量.
struct sample{ int i;};
sample f()
{
struct : sample
{
// there were some members declared here
} x;
x.i = 10;
return x;
}
int main()
{
sample s = f();
cout << s.i << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
ideone上的示例代码:http://www.ideone.com/6Mj8x
PS:因为无障碍原因我改为class
了struct
!