作者hiroki1139 (小波)
看板EE_DSnP
标题[问题] 理解不能的compile error
时间Wed Dec 15 11:26:23 2010
是这样的
在erase的时候我想把BSTreeNode的_data assign成0
结果就出现compile error了
../../include/bst.h: In member function ‘bool
BSTree<T>::erase(BSTree<T>::iterator) [with T = AdtTestObj]’:
adtTest.h:99: instantiated from here
../../include/bst.h:194: error: no match for ‘operator=’ in ‘
((BSTree<AdtTestObj>*)this)->BSTree<AdtTestObj>::_root->BSTreeNode<AdtTestObj>::_data
= 0’
adtTest.h:62: note: candidates are: AdtTestObj& AdtTestObj::operator=(const
AdtTestObj&)
adtTest.h:99: instantiated from here
../../include/bst.h:210: error: no match for ‘operator=’ in ‘
pos.BSTree<AdtTestObj>::iterator::_node->BSTreeNode<AdtTestObj>::_data = 0’
adtTest.h:62: note: candidates are: AdtTestObj& AdtTestObj::operator=(const
AdtTestObj&)
adtTest.h:99: instantiated from here
../../include/bst.h:217: error: no match for ‘operator=’ in ‘
y->BSTreeNode<AdtTestObj>::_data = 0’
adtTest.h:62: note: candidates are: AdtTestObj& AdtTestObj::operator=(const
AdtTestObj&)
../../include/bst.h: In constructor ‘BSTree<T>::BSTree() [with T =
AdtTestObj]’:
我想是没有定义在AdtTest里的=
(好想自己定义><
不知道有没有别的方法呢
还有以下三行也是看不太懂
../../include/bst.h:38: error: no matching function for call to ‘
BSTreeNode<AdtTestObj>::BSTreeNode(int)’
../../include/bst.h:21: note: candidates are: BSTreeNode<T>::BSTreeNode(const
T&, BSTreeNode<T>*, BSTreeNode<T>*, BSTreeNode<T>*) [with T = AdtTestObj]
../../include/bst.h:18: note:
BSTreeNode<AdtTestObj>::BSTreeNode(const BSTreeNode<AdtTestObj>&)
38行和21行分别是BSTree和BSTreeNode的constructor
21> BSTreeNode(const T& d, BSTreeNode<T>* p = 0, BSTreeNode<T>* l = 0,
BSTreeNode<T>* r = 0):
_data(d),_parent(p),_left(l),_right(r) {}
38> BSTree() : _size(0) { _root = new BSTreeNode<T>(0); }
谢谢了^^
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.218.182
1F:推 ric2k1:请检查一下你的 const... 12/15 11:33
2F:推 wwjd123:怎麽有种相似 少一个}的感觉 12/15 11:38
3F:推 johnjohnlin:new BSTreeNode<T>(T())? 12/15 11:45
4F:推 tomap41017:推楼上,你的_data存的是物件不是指标,不可以给0初始 12/15 12:04
5F:→ tomap41017:所以assign _data = 0会编译错误是正常 12/15 12:04
6F:推 wintercobra:可以改用_root = newBSTreeNode<T>( T() ); 12/15 12:12
7F:→ wintercobra:但,改node的constructor成BSTreeNode(const T d, ...) 12/15 12:13
8F:→ hiroki1139:这样不会有memory leak吗@@ 12/15 12:35