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
|