c++ - C++ 静态数据成员初始化异常
问题描述
-std=gnu++17
我使用和-std=gnu++2a
选项使用 gcc-10.1 尝试了这个。如果未注释 A 行,则此代码段将无法编译:
struct Vec3f {
float x, y, z;
Vec3f(float x, float y, float z) : x(x), y(y), z(z) {};
};
struct S {
static inline Vec3f a{1, 1, 1};
static inline auto b = Vec3f(1, 1, 1);
static inline Vec3f c(1, 1, 1); // Line A
};
int main(int, char**) {
Vec3f c(1, 1, 1);
return c.z;
}
产生此错误:
[build] ../main.cpp:16:25: error: expected identifier before numeric constant
[build] static inline Vec3f c(1, 1, 1);
[build] ^
[build] ../main.cpp:16:25: error: expected ‘,’ or ‘...’ before numeric constant
尽管在函数Vec3f c(1, 1, 1);
内部被愉快地使用main
。有什么押韵或理由吗?
解决方案
推荐阅读
- wordpress - WooCommerce 基于单个属性设置产品尺寸(宽度和高度)
- swift - SwiftUI:专门为结构属性设置用户默认值
- exe - 如何在第一次尝试时执行部分脚本?
- performance - 在采样模式下使用 perf 时从 mmap 共享内存中读取
- c# - 无法使用 Microsoft.Office.Interop.Excel 加载文件或程序集 'office, Version=15.0.0.0
- c++ - 控制 cv::Mat 中的图像数据内存
- ios - 如何在 ios Swift 5 中使用多个欧元值总计数组,例如 ["£179.95"、"£199.95"、"£89.95"]
- c - 错误:未定义对 `ruserok` 的引用 - 在为 arm64 编译 PAM-1.1.8 时
- json - 我想在 POSTMAN 中使用 JSON 文件声明响应正文
- c# - 无法创建资源目录路径 Azure