Can a member of a class be named the same name as its type (another class)?

前端 未结 3 2074
半阙折子戏
半阙折子戏 2020-12-20 12:50

Trying to compile the following code on different compilers gives me two different results:

struct S{};
struct T{S S;};
int main(){}

As you

3条回答
  •  醉酒成梦
    2020-12-20 13:43

    This code is ill-formed, no diagnostic required. Like the diagnostic says, if a declaration uses a name and the name has a different meaning than it would have when looked up at the end of the class definition, the programm is illformed, no diagnostic required.

提交回复
热议问题