阅读TeXmacs的代码,我看到了这个:
struct texmacs_input_rep : concrete_struct {
...
};
这是什么意思?
此语法在 C standard 中定义, p113, 但我没有找到它的意思,但那是因为我不知道如何阅读语法规则。
因为 concrete_struct
是另一个 struct
,它包含看起来像构造函数和虚拟析构函数的函数,而且因为我在别处读到 C++ 中的类实际上是 struct
默认带有 public 成员,我猜这是在 C 中使用 struct
进行继承的方式(因为它是 C 标准...)。
这是正确的吗?
最佳答案
它是 C++ 语法并且等效于此:
class texmacs_input_rep : public concrete_struct {
public:
...
};
这是继承类的正常语法,这里texmacs_input_rep
继承自concrete_struct
。
关于 C 中的语法:
您链接到的 C 标准定义 (6.7.2.1):
struct-or-union-specifier: struct-or-union identifieropt { struct-declaration-list } struct-or-union identifier struct-or-union: struct union
So according to C it must be struct
, followed by an optional identifer, followed by {
. Or only struct
followed by an identifer (a forward declaration). In neither case there is room for an additional : ...
in there.
The :
mentioned later in that paragraph of the standard is about bit-field widths, like this;
struct foo {
unsigned a : 4;
unsigned b : 3;
};
这里 a
和 b
只有 4 位和 3 位宽,但这与问题中的语法不同。
关于c++ - C 中的结构声明中的冒号是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1666580/