報(bào)錯(cuò)non-const static data member must be initialized out of line的2
記錄工作中遇到的錯(cuò)誤。
eg.
#include <iostream>
class Cube
{
int static length_ = 2;
};
會(huì)報(bào)錯(cuò)non-const static data member must be initialized out of line
解決方法:
solu-1: 把此靜態(tài)成員變量加設(shè)為const
solu-1-eg.
#include <iostream>
class Cube
{
const?int static length_ = 2;
};
solu-2:把次靜態(tài)成員變量放到類外定義
solu-2-eg.
#include <iostream>
int static length_ = 2;
class Cube
{
};
=reference=
[1]https://blog.csdn.net/nlforever/article/details/9313587
標(biāo)簽: