c++ 类的数据成员初始化
程序员文章站
2022-07-12 22:50:32
...
class First{
public:
int num = 0;//错误
const int num1 = 0;//错误
static int num2 = 0;//错误
static const int num3 = 0;//正确,只有静态常量整型数据成员才可以在类中初始化
string str = "0";//错误
const string str1 = "0";//错误
static string str2 = "0";//错误
static const string str3 = "0";//错误
float fnum = 0;//错误
const float fnum1 = 0;//错误
static float fnum2 = 0;//错误
static const float fnum3 = 0;//错误
};