欢迎光临散文网 会员登陆 & 注册

报错non-const static data member must be initialized out of line的2

2021-12-11 17:45 作者:LogByMax  | 我要投稿

记录工作中遇到的错误。


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

报错non-const static data member must be initialized out of line的2的评论 (共 条)

分享到微博请遵守国家法律