我想我知道为什么我会收到这个错误,但我不确定如何纠正它..
template <typename T>
std::ostream& operator<<(std::ostream& os, const btree<T>& tree) {
queue < btree<T> > q;
class list <node<T>*>::iterator itr = bt.neighbours.begin();
for (; itr != bt.neighbours.end(); itr++) {
os << (*itr)->getItem() << " ";
// add all the btree's connected to this node to the queue
q.push((*itr)->left());
}
}
template <typename T>
class node {
public:
btree <T> * left() { return l; }
private:
btree <T> * l;
}
我得到的错误信息是:
test.cpp:18: instantiated from here
btree.tem:125: error: invalid conversion from 'btree<char>*' to 'unsigned int'
btree.tem:125: error: initializing argument 1 of 'btree<T>::btree(size_t) [with T = char]'
在我看来,因为我正在将指向对象的指针推入队列,队列只接受导致此错误的对象。我迷失了如何解决这个问题,任何帮助都会非常感激!!
提前致谢=]
答案 0 :(得分:2)
更改推送对象的queue::push
语句:
q.push(*((*itr)->left()));