我正在尝试在我的类中创建一个静态字符串:(在我的头文件中)
static string description = "foo";但是我得到了这个错误:
IntelliSense: a member with an in-class initializer must be const如果我把它改成这样:
static const string description = "foo";我得到了这个错误:
IntelliSense: a member of type "const std::string" cannot have an in-class initializer我做错什么了?
发布于 2012-11-08 01:25:34
您可以做的是在头部中声明字符串,并在.cpp中对其进行初始化。
在MyClass.h中
#include <string>
class MyClass
{
static std::string foo;
}在MyClass.cpp中
#include "MyClass.h"
std::string MyClass::foo = "bar"https://stackoverflow.com/questions/13274876
复制相似问题