
c++中可以对类中私有成员中的静态变量初始化吗
1个回答
展开全部
可以。类的所有静态变量都必须在类的外部初始化,格式是:类型名 类名::变量名=初始值;而不管它是私有的还是公有的。如:
class c
{
public:
static int d;
protected:
static int e;
private:
static int f;
};
int c::d=1;
int c::e=2;
int c::f=3;
class c
{
public:
static int d;
protected:
static int e;
private:
static int f;
};
int c::d=1;
int c::e=2;
int c::f=3;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |