google-test and static constexpr member
google-test and static constexpr member
来自FAQ:
如果您的班级有静态数据成员:
// foo.h
class Foo {
...
static const int kBar = 100;
};
您还需要在foo.cc的班级主体外定义它:
const int Foo::kBar; // No initializer here.
否则,您的代码为无效C ,并且可能以意外的方式破裂。特别是,在Google测试比较中使用它(Expect_eq等)将生成"未定义的参考"链接器错误。
如果我使用 static constexpr
,而不是 static const
,我是否仍然在foo.cc中有定义?
在C 11和C 14中,即使在constexpr
的情况下,您也需要单独的foo
定义。但是,对于constexpr
情况,C 17中将不再需要单独的定义。
相关文章:
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 多成员Constexpr结构初始化
- 条件constexpr函数
- constexpr 函数中的非文字(通过 std::is_constant_evaluated)
- Visual C++ constexpr Hints
- 如何确认我的constexpr表达式实际上已经在编译时执行
- 为什么constexpr的性能比正常表达式差
- 是否可以使用if constexpr删除控制流语句
- 要与"if constexpr"一起使用的编译时消息(在预处理器之后)
- 为什么std::isnan 不是 constexpr?
- Constexpr替代了新的放置方式,可以让内存中的对象保持未初始化状态
- 当一个值是非常量但用常量表达式初始化时使用constexpr
- 更多constexpr容器是否需要mark_immutable_if_consexpr
- C++从其他 constexpr 创建 lambda 不能按顺序执行 Constexpr
- constexpr上下文中std::initializer_list的验证
- constexpr构造函数需要常量成员函数时出现问题
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- vs 2015 constexpr变量不恒定,但与2019相比还好吗
- google-test and static constexpr member
- Constexpr non member 函数和引用 Argos