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

来源:互联网 发布:opera for linux 64 编辑:程序博客网 时间:2024/06/05 00:52

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"}; //正确

}

0 0