c++ - 以 .(点)为前缀的结构变量名称需要解释

标签 c++

这是来自 OBS Studio under GitHub 的代码摘录.我未能理解以下内容:

1) struct 关键字后跟结构名称 (obs_encoder_info) 和标签 (opus_encoder_info) 吗?

2) 结构变量如何以 .(dot) 为前缀?它是另一个结构的成员变量吗?

struct obs_encoder_info opus_encoder_info = {
   .id             = "ffmpeg_opus",
   .type           = OBS_ENCODER_AUDIO,
   .codec          = "opus",
   .get_name       = opus_getname,
   .create         = opus_create,
   .destroy        = enc_destroy
};

最佳答案

这是 designated initializers (C++20 起)。

因此它声明了一个名为opus_encoder_info 的对象,类型为obs_encoder_info,其数据成员id 初始化为值"ffmpeg_opus"type 初始化为值OBS_ENCODER_AUDIO,依此类推。

关于c++ - 以 .(点)为前缀的结构变量名称需要解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56746118/

相关文章:

c++ - "expected unqualified-id before ‘.’ token”错误--C++

c++ - 字符字符串数组的初始化程序中的问题

c++ - 将标量乘以 boost.units.quantity(自动类型转换问题?)

c++ - 最新的 OpenGL 应用程序是否必须使用 GLEW?

c# - 将带有动态字符串数组的结构从 C# 发送到 C++ DLL

c++ - C++ 中的哈希函数 SHA1

c++ - 是否存在 valgrind 不会报告现有泄漏/错误的情况

c++ - 在将 void* 转换为任何内容时,我应该使用 static_cast 还是 reinterpret_cast

c++ - 如何调试 msvcp100d.dll 中的崩溃

c++ - 如何避免从整数 0 到指针的隐式转换,作为 vector 的元素