作者herman602 (奸商)
看板C_and_CPP
标题[问题] 用类别建立物件後无法存取其他项目
时间Wed Mar 11 20:22:02 2009
我的主程式是
#include <iostream>
#include "HeapSort.h"
using namespace std;
int main()
{
HeapSort case1();
case1.show();
system("pause");
return 0;
}
HeapSort.h的内容是
class HeapSort
{
public:
HeapSort();
~HeapSort();
int get_size();
void interchange(int *a, int *b);
bool check_node_is_exist(int *node);
void compare_value_and_interchange(int *parent, int *child_1, int
*child_2);
void change_node();
void show();
private:
int size, *data, counter, index;
};
然後编译出来的错误讯息是(dev-c)
request for member `show' in `case1', which is of non-class type `HeapSort ()()'
Visual Studio 2008说是
error C2228: '.show' 的左边必须有类别/结构/等位
问题出在哪里@@?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.195.208.178
1F:→ herman602:class实做部分我没贴出来 ... 03/11 20:22
2F:推 littleshan: HeapSort case1(); 改成 HeapSort case1; 03/11 20:24
3F:→ littleshan:否则compiler会误以为case1是个回传HeapSort的函式 03/11 20:24
我一开始也没有括弧
可是就出现
[Linker error] undefined reference to `HeapSort::HeapSort()'
[Linker error] undefined reference to `HeapSort::show()'
[Linker error] undefined reference to `HeapSort::~HeapSort()'
[Linker error] undefined reference to `HeapSort::~HeapSort()'
Visual Studio 2008则出现
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall
HeapSort::~HeapSort(void)" (??1HeapSort@@QAE@XZ) 在函式 _main 中被参考
1>main.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall
HeapSort::show(void)" (?show@HeapSort@@QAEXXZ) 在函式 _main 中被参考
1>main.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall
HeapSort::HeapSort(void)" (??0HeapSort@@QAE@XZ) 在函式 _main 中被参考
实做部分在这
http://src.wtgstudio.com/?n708kU
※ 编辑: herman602 来自: 123.195.208.178 (03/11 20:35)
4F:→ herman602:已经解决 感谢yehsd XD" 03/11 21:29