【发布时间】:2017-03-13 12:33:24
【问题描述】:
来自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++ googletest