由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - error LNK2001:的错误如何改正?
相关主题
[合集] 为什么下面代码总是调试通不过?关于C/C++里的Static variable的memory allocation/initializa
这个程序为什么不能运行?C++: Static initialization dependency
static initialization dependency c++Re: can destructor be static?
static variable存在heap还是stack?Test your C++ knowledge...
static 变量放在哪里?C++Global(static) variable initialization question
c++ 不自动initialize变量么?When are data members initialized? what about static data m
再问C++初始化问题。will static/global var be initialized to 0 in C/C++
static vector 怎么 initialize ?A question about c++ pointer
相关话题的讨论汇总
话题: static话题: heapsort话题: class话题: heap话题: lnk2001
进入Programming版参与讨论
1 (共1页)
w****h
发帖数: 212
1
如果程序报错:
error LNK2001: unresolved external symbol "public: static int HeapSort::
heap_size" (?heap_size@HeapSort@@2HA)
如何解决?
以前遇到这个问题,似乎是开始不应该选择console application,应该用empty
project。当时重建empty project就解决了。
但现在再次遇到,在VC 2008 express edition,代码文件很多,不知道如何设置?难
道要重新建一个empty project吗?
多谢。
K*****n
发帖数: 65
2
Can you do a search in all cpp of your project for
"int HeapSort::heap_size"?
static class data member gets no memory allocated, you need to define one
like global variables.
say
int HeapSort::heap_size = 100; //initialization is optional
w****h
发帖数: 212
3
我开始在头文件里定义的是static int heap_size;
为什么不能定义static?

【在 K*****n 的大作中提到】
: Can you do a search in all cpp of your project for
: "int HeapSort::heap_size"?
: static class data member gets no memory allocated, you need to define one
: like global variables.
: say
: int HeapSort::heap_size = 100; //initialization is optional

K*****n
发帖数: 65
4
I know you define
static int heap_size;
in your class HeapSort in header file.
static class member is shared by all its class objects, so it gets no room
in objects. That's why you need make ANOTHER GLOBAL define in
your cpp file.
int HeapSort::heap_size = 100; //initialization is optional
K*****n
发帖数: 65
5
Here is a quote from http://www.cprogramming.com/tutorial/statickeyword.html
An important detail to keep in mind when debugging or implementing a program
using a static class member is that you cannot initialize the static class
member inside of the class. In fact, if you decide to put your code in a
header file, you cannot even initialize the static variable inside of the
header file; do it in a .cpp file instead. Moreover, you are required to
initialize the static class member or it will not b
w****h
发帖数: 212
6
thanks!

program
class

【在 K*****n 的大作中提到】
: Here is a quote from http://www.cprogramming.com/tutorial/statickeyword.html
: An important detail to keep in mind when debugging or implementing a program
: using a static class member is that you cannot initialize the static class
: member inside of the class. In fact, if you decide to put your code in a
: header file, you cannot even initialize the static variable inside of the
: header file; do it in a .cpp file instead. Moreover, you are required to
: initialize the static class member or it will not b

1 (共1页)
进入Programming版参与讨论
相关主题
A question about c++ pointerstatic 变量放在哪里?C++
stack/heap corruptionc++ 不自动initialize变量么?
VC++ does not support strlen()再问C++初始化问题。
[合集] which design pattern is used if a static variable insidstatic vector 怎么 initialize ?
[合集] 为什么下面代码总是调试通不过?关于C/C++里的Static variable的memory allocation/initializa
这个程序为什么不能运行?C++: Static initialization dependency
static initialization dependency c++Re: can destructor be static?
static variable存在heap还是stack?Test your C++ knowledge...
相关话题的讨论汇总
话题: static话题: heapsort话题: class话题: heap话题: lnk2001