SNpn
SNpn

Reputation: 2207

error invalid conversion C++

I think I know why I am getting this error, but I'm not sure how to correct it..

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;
}

the error message I'm getting is:

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]'

it seems to me, that because I'm pushing a pointer to an object into the queue, where the queue only accepts the object it is causing this error. I'm lost in how to fix this problem, any help would be most appreciated!!

Thanks in advance =]

Upvotes: 0

Views: 203

Answers (1)

iammilind
iammilind

Reputation: 69988

Change the queue::push statement for pushing an object:

q.push(*((*itr)->left()));

Upvotes: 2

Related Questions