c++ - `synonym` 中的 `typedef` 是强制性的吗?

标签 c++ syntax typedef

我在代码审查中遇到过这个:

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/

相关文章:

c++ - "names which are not lvalues"是什么?

c++ - 在 Poco SQLite 中的表之间加入

c++ - 这个语法是什么? C++

c - 像 "typedef int (f)(void)"这样带括号的 typedef 是什么意思?它是一个函数原型(prototype)吗?

c# - DLL导入: Unable to find Entry Point "fnMultiply" in DLL "ImportDLL"

c++ - 根据某些元数据在运行时转换参数包值

c++ - 如何实现两个可以相互访问的结构体?

javascript - 使用函数作为参数

c++ - 使用单独编译时返回 typedef 类型

c - 重新定义;先前的定义是 'typedef' 错误