2017-03-13 48 views
1

FAQ谷歌測試和靜態constexpr成員

如果你的類有一個靜態數據成員:

// foo.h 

class Foo { 
    ... 
    static const int kBar = 100; 
}; 

您還需要定義它的類人體foo.cc中之外:

const int Foo::kBar; // No initializer here.

否則你的代碼是無效C++,並在unexpect可能會中斷ed方式。特別是,在Google Test比較斷言(EXPECT_EQ等)中使用它會生成「未定義參考」鏈接器錯誤。

如果不是static const我使用static constexpr,我應該還是在foo.cc中有定義嗎?

回答