报错non-const static data member must be initialized out of line的2
记录工作中遇到的错误。
eg.
#include <iostream>
class Cube
{
int static length_ = 2;
};
会报错non-const static data member must be initialized out of line
解决方法:
solu-1: 把此静态成员变量加设为const
solu-1-eg.
#include <iostream>
class Cube
{
const int static length_ = 2;
};
solu-2:把次静态成员变量放到类外定义
solu-2-eg.
#include <iostream>
int static length_ = 2;
class Cube
{
};
=reference=
[1]https://blog.csdn.net/nlforever/article/details/9313587