Can you use the sizeof one member when declaring another member?

后端 未结 2 1405
情歌与酒
情歌与酒 2021-01-04 01:48

Is this legal C++?

struct foo
{
  int a[100];
  int b[sizeof(a) / sizeof(a[0])];
};

GCC 4.6 accepts it, but MSVC 2012 doesn\'t. It seems li

2条回答
  •  隐瞒了意图╮
    2021-01-04 02:16

    This was illegal in C++03 because these members are nonstatic datamembers.

    Starting from C++11 this is legal since in an unevaluated operand you can use nonstatic datamembers without having a corresponding object.

提交回复
热议问题