作者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