什么时候定义静态数据成员? [英] When is a static data member defined?

查看:101
本文介绍了什么时候定义静态数据成员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,S :: c完全定义了什么点?

#include< iostream>


使用std :: cout;

使用std :: endl;

使用std :: ostream;


class C {

int _v;

public:

C(const int& v)

:_v(v)

{}

ostream&打印(ostream& out)const

{

退出<< _v;

}

};


struct S {

static const C c; < br $>
};


const CS :: c = C(42);


ostream& operator<<(ostream& out,const S& s)

{

scprint(out);

返回;

}

int main()

{

s s;

cout< < s<<结束;

返回0;

}


-

如果我们的假设是关于任何事情,而不是关于某一个或多个特定的东西,然后我们的推论构成数学。因此,数学可能被定义为我们永远不知道我们所讨论的是什么,以及我们所说的是否属实的主题。 - Bertrand

Russell

In the following code, at what point is S::c fully defined?

#include <iostream>

using std::cout;
using std::endl;
using std::ostream;

class C {
int _v;
public:
C(const int& v)
:_v(v)
{}

ostream& print(ostream& out) const
{
return out << _v;
}
};

struct S {
static const C c;
};

const C S::c = C(42);

ostream& operator<<(ostream& out, const S& s)
{
s.c.print(out);
return out;
}
int main()
{
S s;
cout << s << endl;
return 0;
}

--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell

推荐答案

Steven T. Hatton写道:
Steven T. Hatton wrote:
在下面的代码中,S :: c在什么时候完全定义了?
#include< iostream>
[...]
const CS :: c = C (42);


这里。

[...]
int main()
{s / s / s / > cout<< s<< endl;
返回0;
}
In the following code, at what point is S::c fully defined?

#include <iostream>
[...]
const C S::c = C(42);
Here.
[...]
int main()
{
S s;
cout << s << endl;
return 0;
}




V



V


Steven T. Hatton写道:
Steven T. Hatton wrote:
在下面的代码中,S :: c在什么时候完全定义了?

#include< iostream>

使用std :: cout;
使用std :: endl;
使用std :: ostream;

C类{
int _v;
公众:
C(const int& v)
:_v(v)
{}

ostream&打印(ostream& out)const
{
返回<< _v;
}
};

struct S {
static const C c;
};

const CS: :c = C(42);
In the following code, at what point is S::c fully defined?

#include <iostream>

using std::cout;
using std::endl;
using std::ostream;

class C {
int _v;
public:
C(const int& v)
:_v(v)
{}

ostream& print(ostream& out) const
{
return out << _v;
}
};

struct S {
static const C c;
};

const C S::c = C(42);



这里。


-

Ioannis Vranos

http://www23.brinkster.com/noicys


Victor Bazarov写道:
Victor Bazarov wrote:
Steven T. Hatton写道:
Steven T. Hatton wrote:
在下面的代码中,在什么时候完全定义了S :: c吗?
#include< iostream>
[...]
const CS :: c = C(42);
In the following code, at what point is S::c fully defined?

#include <iostream>
[...]
const C S::c = C(42);



这里。



Here.




我同意。在什么时候内存(通常)分配?

-

如果我们的假设是关于任何事情而不是关于某个或多个某个或多个美元$ b特定的东西,然后我们的推论构成数学。因此,数学可能被定义为我们永远不知道我们所讨论的是什么,以及我们所说的是否属实的主题。 - Bertrand

Russell



I agree. At what point is the memory (typically) allocated?
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell


这篇关于什么时候定义静态数据成员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆