[問題] template class裡做 recurssive call

看板C_and_CPP (C/C++)作者 (研修医当直)時間13年前 (2012/12/30 13:30), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Code::Bloacks@Win7 32bits Compiler:GCC 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) NULL 問題(Question): 我是想在一個node中做postoder traversal 但是用recurssive call function會過不了compiler 我知道calss A { A a ;} compiler可能會有問題(先有雞 先有蛋?) 這裡也是同樣的問題嗎? 有沒有辦法改code讓compiler能過? 感謝。 錯誤結果(Wrong Output): C:\Users\Home\Desktop\binomial.cpp||In instantiation of 'void BinomialNode<T>::postorder() [with T = int]':| C:\Users\Home\Desktop\binomial.cpp|60|required from 'void BinomialTree<T>::postorder() [with T = int]'| C:\Users\Home\Desktop\binomial.cpp|151|required from 'void BinomialHeap<T>::postorder() [with T = int]'| C:\Users\Home\Desktop\binomial.cpp|162|required from here| C:\Users\Home\Desktop\binomial.cpp|30|error: 'class BinomialNode<int>' has no member named 'postoder'| ||=== Build finished: 1 errors, 4 warnings (0 minutes, 0 seconds) ===| 程式碼(Code):(請善用置底文網頁, 記得排版) template <class T> class BinomialNode { public: T data; BinomialNode<T>* parent; BinomialNode<T>* child; BinomialNode<T>* sibling; BinomialNode(T data) { parent=child=sibling=NULL; this->data=data; } void postorder(); }; template <class T> void BinomialNode<T>::postorder() { if(child!=NULL)child->postorder(); if(sibling!=NULL)sibling->postoder(); cout << data << endl; } -- ║ ║ ╗ ╔═ ╠═╣╔╣ ╔╗╚╗ ║ ║╚╩ ║║═╝ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.102.128.144

12/30 14:34, , 1F
你打錯字? s/postoder/postorder/g
12/30 14:34, 1F

12/30 14:51, , 2F
哈哈 thx. 我耍白痴了.
12/30 14:51, 2F

12/30 22:00, , 3F
一樓是vim吧,原PO是codeblocks on windows XD
12/30 22:00, 3F
文章代碼(AID): #1Gtz6Jmp (C_and_CPP)
文章代碼(AID): #1Gtz6Jmp (C_and_CPP)