I want to achieve something like this:
class MyTest: public ::testing::Test {
public:
const int myConstInt = 23;
}
TEST_F(MyTest, MyTest1) {... use myConstInt ...}
But recollecting from Item 4 of EffectiveCPP, the initialization is not guaranteed in this manner and there is a chance of undefined behavior.
Let's say the above is Method 1.
I can think of two other methods to achieve this:
Method 2: Initializer list of myConstStr using a MyTest constructor.
Method 3: Make it constexpr - since the value is set at compile time I shouldnt face any initialization issues during runtime.
Which would be the correct way to go about this? Also Effective CPP is a relatively old book - Does the discussion of Item 4 still fully apply?