LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-23-2004, 01:54 PM   #1
Config
Member
 
Registered: Jan 2001
Location: Switzerland
Distribution: Gentoo
Posts: 376

Rep: Reputation: 30
Stl iterator woes


I need some help guys - I'm writing a little program for cs... and my problem is as follows:

I've got two classes, edge and Node. In class node, I've got a list:

list<edge> edges;

In a function of this class, I'm getting a reference to a priority queue of type:

priority_queue<Edge> &neighbours

What I want to do now, is insert some of the items of the list in the priority queue.
I've created an iterator, which I later correctly initialize:

list<Edge>::iterator position;

Now, I'm trying to insert the the data from the iterator in the priority queue:

neighbours.push(*position);

This does not work - the compiler errors I get are as follows:

/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.0/include/g++-v3/bits/vector.tcc: In member function `Edge& Edge::operator=(const Edge&)':
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.0/include/g++-v3/bits/vector.tcc:238: instantiated from `void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator<_Tp*, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = Edge, _Alloc = std::allocator<Edge>]'
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.0/include/g++-v3/bits/stl_vector.h:564: instantiated from `void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = Edge, _Alloc = std::allocator<Edge>]'
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.0/include/g++-v3/bits/stl_queue.h:431: instantiated from `void std::priority_queue<_Tp, _Sequence, _Compare>::push(const typename _Sequence::value_type&) [with _Tp = Edge, _Sequence = std::vector<Edge, std::allocator<Edge> >, _Compare = std::less<Edge>]'
Node.cc:33: instantiated from here
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.0/include/g++-v3/bits/vector.tcc:238: error: non-static reference member `Node&Edge::target', can't use default assignment operator
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.0/include/g++-v3/bits/stl_function.h: In member function `bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = Edge]':
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.0/include/g++-v3/bits/stl_heap.h:166: instantiated from `void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Edge*, std::vector<Edge, std::allocator<Edge> > >, _Distance = long int, _Tp = Edge, _Compare = std::less<Edge>]'
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.0/include/g++-v3/bits/stl_heap.h:203: instantiated from `void std::push_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Edge*, std::vector<Edge, std::allocator<Edge> > >, _Compare = std::less<Edge>]'
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.0/include/g++-v3/bits/stl_queue.h:432: instantiated from `void std::priority_queue<_Tp, _Sequence, _Compare>::push(const typename _Sequence::value_type&) [with _Tp = Edge, _Sequence = std::vector<Edge, std::allocator<Edge> >, _Compare = std::less<Edge>]'
Node.cc:33: instantiated from here
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.0/include/g++-v3/bits/stl_function.h:227: error: no match for 'operator<' in '__x < __y'
Node.h:36: note: candidates are: bool operator<(Edge&, Edge&)

Any ideas? Thanks a lot
 
Old 06-23-2004, 03:07 PM   #2
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
The last few error messages suggest you need to change the implementation of the '<' operator on Edges. Maybe it needs to take Edge arguments rather than ( Edge & ) arguments?

Alex
 
Old 06-23-2004, 03:20 PM   #3
Config
Member
 
Registered: Jan 2001
Location: Switzerland
Distribution: Gentoo
Posts: 376

Original Poster
Rep: Reputation: 30
Wow - already quite some errors are gone - thanks - a few still remain - I'm really new to stl (Used it for the first time now - so I'm just posting the errors here:

/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.0/include/g++-v3/bits/vector.tcc: In member function `Edge& Edge::operator=(const Edge&)':
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.0/include/g++-v3/bits/vector.tcc:238: instantiated from `void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterator<_Tp*, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp = Edge, _Alloc = std::allocator<Edge>]'
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.0/include/g++-v3/bits/stl_vector.h:564: instantiated from `void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = Edge, _Alloc = std::allocator<Edge>]'
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.0/include/g++-v3/bits/stl_queue.h:431: instantiated from `void std::priority_queue<_Tp, _Sequence, _Compare>::push(const typename _Sequence::value_type&) [with _Tp = Edge, _Sequence = std::vector<Edge, std::allocator<Edge> >, _Compare = std::less<Edge>]'
Node.cc:33: instantiated from here
/usr/lib/gcc/x86_64-pc-linux-gnu/3.4.0/include/g++-v3/bits/vector.tcc:238: error: non-static reference member `Node&Edge::target', can't use default assignment operator

They still look very cryptic to me - but thanks already :D
 
Old 06-23-2004, 05:22 PM   #4
llama_meme
Member
 
Registered: Nov 2001
Location: London, England
Distribution: Gentoo, FreeBSD
Posts: 590

Rep: Reputation: 30
Could you post your implementation of the '=' operator for Edge?

Alex
 
Old 06-23-2004, 05:31 PM   #5
Config
Member
 
Registered: Jan 2001
Location: Switzerland
Distribution: Gentoo
Posts: 376

Original Poster
Rep: Reputation: 30
I just saw that - but I was wondering what it was needed for - I'll find out eventually

Thanks for the help
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert between list<T>::iterator and T* shreks Programming 2 08-26-2004 05:27 PM
compile error while returning STL iterator as object * rameshmiraje Programming 2 06-20-2004 01:50 PM
error in assigning the iterator to refrence varaible ashwinipahuja Programming 1 06-18-2004 05:55 AM
_gnu Iterator Error-g++ ashwinipahuja Programming 4 05-26-2004 11:17 PM
Problem in Iterator- g++ ashwinipahuja Programming 1 04-30-2004 12:08 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration