我在代码审查中遇到过这个:
typedef struct C { int i; };
它编译。</p>
除了它是 C 风格,其中结构在一个单独的“命名空间”中,并且需要进行类型定义以便以后使用,我发现很奇怪没有用这个类型定义定义任何东西......
那么:typedef
不需要类型参数和别名参数吗?
最佳答案
快速浏览一下 n3225 并没有显示任何要求存在名称的要求。最接近的文本只是说
In a simple-declaration, the optional init-declarator-list can be omitted only when declaring a class (clause 9) or enumeration (7.2), that is, when the decl-specifier-seq contains either a class-specifier, an elaborated- type-specifier with a class-key (9.1), or an enum-specifier.
所以你的代码似乎是有效的,但我觉得它闻起来很糟糕。
关于c++ - `synonym` 中的 `typedef` 是强制性的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4690886/