c++11类的就地初始化问题

1 c++98只能对静态的常量能进行就地初始化,其他的不行 struct  st { static const int a=10;//yes int a

1 c++98只能对静态的常量能进行就地初始化,其他的不行

struct  st

{

static const int a=10;//yes

int a=10;//no

}

   c++11可以对非静态的成员变量就地初始化,

struct st

{

int a=10;//yes

}

  但对静态的非常量的成员变量c++98和c++11保持了一致性,即需到头文件以外的地方去定义它

struct st

{

static int a=10;//c++98和c++11都不行

}


2 结构内用()和{}初始化不同:前者不可以后者可以

struct ini

{

string s("Gimy"); //错误

string s{"Gimy"}; //正确

}