作者rf0914 (<-使用者代号)
看板EE_DSnP
标题[问题] g++
时间Thu Dec 1 22:33:54 2011
刚刚发现相同的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
1F:→ shryuhuai:stack和vector等等不给参数的话就会是empty,不用写 = 0 12/01 23:52
2F:→ rf0914:可是我不给参数就他就说我缺少预设引数... 12/01 23:58
3F:推 ric2k1:感觉 stack = 0 怪怪的... 12/02 00:35
4F:→ ric2k1:那 stack<BSTreeNode<T>*> t = stack<BSTreeNode<T>*>(0)呢 12/02 00:36
5F:→ rf0914:还是一样新版可以旧版不行耶~ 12/02 00:46
6F:推 shryuhuai:那stack<BSTreeNode<T>*> t = stack<BSTreeNode<T>*>()? 12/02 09:17
7F:→ rf0914:楼上的就两边都OK了!!! 感谢!! 12/03 00:58