如果要宣告成
static const float STATIC_FLOAT = 1.F;
則Compiler會出現「a member of type "const float" cannot have a in-class initializer」
因此,如想要在class內宣告靜態的float,則需先在class內宣告個靜態的float,但不給予值。並在*.cpp給定此常數值即可:
*.h
class CTestClass
{
static cosnt float STATIC_FLOAT;
...
...
}
*.cpp
const flaot CTestClass::STATIC_FLOAT = 1.F;
參考連結:static const float in C++. why not?
No comments:
Post a Comment