I have a class source file Foo.cpp
and I need to define IntVal
constant only for local use by class methods.
// Option 1
const int IntVal = 5;
// Option 2
static const int IntVal = 5;
// Option 3
namespace {
const int IntVal = 5;
}
int Foo::GetValue()
{
return this->value + IntVal;
}
Which one is preferred?
constexpr static some_type some_name = some_value;
constexpr some_type some_name = some_value;
const
objects defined at file scope are by defaultstatic
, so Option 1 and Option 2 are the same.