【发布时间】:2015-03-20 20:33:47
【问题描述】:
#include"stdafx.h"
#include"iostream"
using namespace std;
static class base{
public:
int i = 3;
};
int main(){
base ob;
system("pause");
return 0;
}
请告诉我,类声明中的“静态”是什么?
【问题讨论】:
-
That is not legal。它不应该编译。它最初可能是变量声明的一部分,例如:
static class X{...} my_x_variable;,但不在此代码中。 -
It's invalid syntax! 但可能会被其他编译器错误隐藏。
-
@Trinimon:您提供的链接实际上无助于回答 OP 的问题。主要是因为它涵盖了
static的有效使用,并且OP 使用它的方式是无效的。但是,我可以确认它确实在 Visual Studio 2013 中编译(尽管有一个警告static被忽略) -
一切都编译,没有编译错误。 Visual Studio 2013
-
使用this online compiler 我得到:main.cpp(6):警告 C4091:'static':当没有声明变量时,'base' 左侧被忽略。阅读您的编译器输出。
标签: c++ class visual-studio-2013 static