[問題] g++

看板EE_DSnP作者 (<-使用者代號)時間12年前 (2011/12/01 22:33), 編輯推噓2(205)
留言7則, 3人參與, 最新討論串1/3 (看更多)
剛剛發現相同的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

12/01 23:52, , 1F
stack和vector等等不給參數的話就會是empty,不用寫 = 0
12/01 23:52, 1F

12/01 23:58, , 2F
可是我不給參數就他就說我缺少預設引數...
12/01 23:58, 2F

12/02 00:35, , 3F
感覺 stack = 0 怪怪的...
12/02 00:35, 3F

12/02 00:36, , 4F
那 stack<BSTreeNode<T>*> t = stack<BSTreeNode<T>*>(0)呢
12/02 00:36, 4F

12/02 00:46, , 5F
還是一樣新版可以舊版不行耶~
12/02 00:46, 5F

12/02 09:17, , 6F
那stack<BSTreeNode<T>*> t = stack<BSTreeNode<T>*>()?
12/02 09:17, 6F

12/03 00:58, , 7F
樓上的就兩邊都OK了!!! 感謝!!
12/03 00:58, 7F
文章代碼(AID): #1Erv1Mq6 (EE_DSnP)
討論串 (同標題文章)
完整討論串 (本文為第 1 之 3 篇):
問題
2
7
問題
2
6
問題
1
1
文章代碼(AID): #1Erv1Mq6 (EE_DSnP)