由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 这个程序为什么不能运行?
相关主题
error LNK2001:的错误如何改正?inline function是否可以递归?
VC++ does not support strlen()C++怎样设置全局变量
recursive template?C++里 variable declaration 有什么用?
class D:public B;[合集] (c++)为什么不能把这个function的definition放到class里
c++ does not check const for extern variable?关于C++ STL编译的疑问
[合集] 为什么不能: declare a static memeber func[合集] 问个及其初级问题。c++
请问如何把初始化一个const 的vector (or array) in a class?vs2008下c++的go to definiton 直接跳到了declaration. 怎么解决?
in-class static member question[合集] 为什么下面代码总是调试通不过?
相关话题的讨论汇总
话题: static话题: int话题: class话题: definition
进入Programming版参与讨论
1 (共1页)
j*****j
发帖数: 115
1
class A
{
static int a;
public:
static ini(int b)
{
a=b;
}
};
int main()
{
A a1;
a1.ini(3);
}
报错:
const error LNK2001: unresolved external symbol "private: static int A::a" (
?a@A@@0HA)
谢谢
l*****d
发帖数: 359
2
it seems you have to define a just below the class declaration:
int A::a;
then it should be ok.

【在 j*****j 的大作中提到】
: class A
: {
: static int a;
: public:
: static ini(int b)
: {
: a=b;
: }
: };
: int main()

l*****d
发帖数: 359
3
The declaration of a static data member in the member list of a class is not
a definition. The definition of a static data member is equivalent to an
external variable definition. You must define the static member outside of
the class declaration in namespace scope.
For example:
class X
{
public:
static int i;
};
int X::i = 0; // definition outside class declaration
1 (共1页)
进入Programming版参与讨论
相关主题
[合集] 为什么下面代码总是调试通不过?c++ does not check const for extern variable?
帮忙!!! 需要比较两文件, 有包子相送 (转载)[合集] 为什么不能: declare a static memeber func
一道面试怪题C++. (转载)请问如何把初始化一个const 的vector (or array) in a class?
Any better way to declare a function?in-class static member question
error LNK2001:的错误如何改正?inline function是否可以递归?
VC++ does not support strlen()C++怎样设置全局变量
recursive template?C++里 variable declaration 有什么用?
class D:public B;[合集] (c++)为什么不能把这个function的definition放到class里
相关话题的讨论汇总
话题: static话题: int话题: class话题: definition