c++ - C 中的结构声明中的冒号是什么意思?

标签 c++ c

阅读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;
};

这里 ab 只有 4 位和 3 位宽,但这与问题中的语法不同。

关于c++ - C 中的结构声明中的冒号是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1666580/

相关文章:

C++:编译对不相关的派生类、错误或功能的函数调用?

c - 我如何在 C 的后台执行()进程?

c - 套接字 recv() 卡在带有 MSG_WAITALL 的大消息上

c - 为什么编译器不优化这个初始化?

c++ - OS X 上的 __LP64__ --> Snow Leopard 等价物?

c++ - 有没有办法在不手动查找的情况下获取数组的大小?

c++ - future 选择哪一个,c++还是python2.x/3.x

c++ - 通过引用或指针共享对象

c - 有没有一个函数可以将char数组输入的数字转换为int数组?

c - Flex 分析器 -- bash 语法错误接近意外标记 '('