[問題] 用類別建立物件後無法存取其他項目

看板C_and_CPP (C/C++)作者 (奸商)時間16年前 (2009/03/11 20:22), 編輯推噓1(103)
留言4則, 2人參與, 最新討論串1/1
我的主程式是 #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

03/11 20:22, , 1F
class實做部分我沒貼出來 ...
03/11 20:22, 1F

03/11 20:24, , 2F
HeapSort case1(); 改成 HeapSort case1;
03/11 20:24, 2F

03/11 20:24, , 3F
否則compiler會誤以為case1是個回傳HeapSort的函式
03/11 20:24, 3F
我一開始也沒有括弧 可是就出現 [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)

03/11 21:29, , 4F
已經解決 感謝yehsd XD"
03/11 21:29, 4F
文章代碼(AID): #19jwpist (C_and_CPP)
文章代碼(AID): #19jwpist (C_and_CPP)