Can unnamed structures inherit?

后端 未结 2 909
遥遥无期
遥遥无期 2021-02-11 16:06

The following looks like a compilation error :

struct : Base { };

Yet when used [1] it seems to work :

#include <         


        
2条回答
  •  我在风中等你
    2021-02-11 16:43

    Your first example, because it doesn't declare anything, shows an attempt at an anonymous struct (which is not allowed - 7/3) rather than an unnamed one (which is).

    The grammar in 9/1 of the C++11 standard seems to allow an unnamed class to have a base, so I think your second example is fine.

提交回复
热议问题