看板 EE_DSnP 關於我們 聯絡資訊
剛剛發現相同的code用不同版本的g++ compile好像會有不一樣的結果耶... 以下是用 Ubuntu 10.04 g++ 4.4.3 顯示的錯誤訊息 In file included from adtTest.h:53, from adtTest.cpp:10: ../../include/bst.h: In constructor ‘ BSTree<T>::iterator::iterator(BSTreeNode<T>*, std::stack<BSTreeNode<T>*, std::deque<BSTreeNode<T>*, std::allocator<BSTreeNode<T>*> > >, bool) [with T = AdtTestObj]’: ../../include/bst.h:105: instantiated from ‘BSTree<AdtTestObj>::iterator’ adtTest.h:90: instantiated from here ../../include/bst.h:105: error: default argument for parameter of type ‘ std::stack<BSTreeNode<AdtTestObj>*, std::deque<BSTreeNode<AdtTestObj>*, std::allocator<BSTreeNode<AdtTestObj>*> > >’ has type ‘int’ make[1]: *** [adtTest.o] Error 1 make: *** [main] Error 2 用 Ubuntu 11.10 g++ 4.6.1 則是順利通過... 而不通過的原因似乎是iterator的constructor的問題 在我的code是寫 iterator(BSTreeNode<T>* n=0, stack< BSTreeNode<T>* > t=0,......){...} 雖然當下覺得stack不知道能不能這樣亂設初值 不過反正compile能過就也沒想那麼多了 沒想到現在都寫完了才在不同版本的compiler上出了問題 不知道這該如何解決呢? 如果同一份code老師不能compile我是不是就gg了?? @@ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.243.229
shryuhuai:stack和vector等等不給參數的話就會是empty,不用寫 = 0 12/01 23:52
rf0914:可是我不給參數就他就說我缺少預設引數... 12/01 23:58
ric2k1:感覺 stack = 0 怪怪的... 12/02 00:35
ric2k1:那 stack<BSTreeNode<T>*> t = stack<BSTreeNode<T>*>(0)呢 12/02 00:36
rf0914:還是一樣新版可以舊版不行耶~ 12/02 00:46
shryuhuai:那stack<BSTreeNode<T>*> t = stack<BSTreeNode<T>*>()? 12/02 09:17
rf0914:樓上的就兩邊都OK了!!! 感謝!! 12/03 00:58