Joh*_*ohn 5 c++ int initialization static-members
我正在尝试以下操作并在两个日志语句之间导致模拟器崩溃。有什么不对?
protected:
static int maxSize;
public:
static void setFontSizeRange(int max) {
Log("here %d->%d", max, maxSize);
maxSize = max;
Log("ok");
}
Run Code Online (Sandbox Code Playgroud)
我可以获取日志来重现参数,但它在输出静态成员之前崩溃(因此上面显示的第一个日志在引用该参数时将不起作用)。
谢谢。
您应该定义静态成员。
class Something
{
protected:
static int maxSize;
public:
static void setFontSizeRange(int max) {
Log("here %d->%d", max, maxSize);
maxSize = max;
Log("ok");
}
}; // class declaration ends here...
int Something::maxSize = 0;
Run Code Online (Sandbox Code Playgroud)