const 變數 'variable' 可以在編譯時期計算。 請考慮使用
constexpr(con.5)
備註
針對常數使用 constexpr ,其值在編譯時期為已知。 (Con.5)
程式碼分析名稱:USE_CONSTEXPR_RATHER_THAN_CONST
範例
const int foo = 1234; // C26814 reported here.
constexpr int getMagicNumber()
{
return 42;
}
void bar()
{
const int myval = 3; // C26814 reported here
const int magicNumber = getMagicNumber(); // C26814 reported here.
}