Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > CAnnot find the compilation error in this circular list

Reply
Thread Tools

CAnnot find the compilation error in this circular list

 
 
Vince
Guest
Posts: n/a
 
      11-29-2004
Hi,

I am not used to template and I cannot find what's wrong with this code :

Compiler(MSVS 7) complains at line :
class iterator : public std::iterator<...



Here is the source code

#include <iostream>
#include <list>
#include <string>
using namespace std;

template<class T>
class Ring {
list<T> lst;
public:
// Declaration necessary so the following
// 'friend' statement sees this 'iterator'
// instead of std::iterator:
class iterator;
friend class iterator;
class iterator : public std::iterator<
std::bidirectional_iterator_tag,T,ptrdiff_t>{
list<T>::iterator it;
list<T>* r;
public:
// "typename" necessary to resolve nesting:
iterator(list<T>& lst,
const typename list<T>::iterator& i)
: r(&lst), it(i) {}
bool operator==(const iterator& x) const {
return it == x.it;
}
bool operator!=(const iterator& x) const {
return !(*this == x);
}
list<T>::reference operator*() const {
return *it;
}
iterator& operator++() {
++it;
if(it == r->end())
it = r->begin();
return *this;
}
iterator operator++(int) {
iterator tmp = *this;
++*this;
return tmp;
}
iterator& operator--() {
if(it == r->begin())
it = r->end();
--it;
return *this;
}
iterator operator--(int) {
iterator tmp = *this;
--*this;
return tmp;
}
iterator insert(const T& x){
return iterator(*r, r->insert(it, x));
}
iterator erase() {
return iterator(*r, r->erase(it));
}
};
void push_back(const T& x) {
lst.push_back(x);
}
iterator begin() {
return iterator(lst, lst.begin());
}
int size() { return lst.size(); }
};



 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      11-29-2004
Vince wrote:
> I am not used to template and I cannot find what's wrong with this code :
>
> Compiler(MSVS 7) complains at line :
> class iterator : public std::iterator<...


Have you tried adding #include <iterator> ? Just a guess...

>
> [...]


V
 
Reply With Quote
 
 
 
 
Vince
Guest
Posts: n/a
 
      11-29-2004
No it doesn't work.

"Victor Bazarov" <(E-Mail Removed)> a écrit dans le message de news:
0yMqd.11492$(E-Mail Removed)09.us.to.verio .net...
> Vince wrote:
>> I am not used to template and I cannot find what's wrong with this code :
>>
>> Compiler(MSVS 7) complains at line :
>> class iterator : public std::iterator<...

>
> Have you tried adding #include <iterator> ? Just a guess...
>
>>
>> [...]

>
> V



 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      11-29-2004
Vince wrote:
> No it doesn't work.
>
> "Victor Bazarov" <(E-Mail Removed)> a écrit dans le message de news:
> 0yMqd.11492$(E-Mail Removed)09.us.to.verio .net...
>
>>Vince wrote:
>>
>>>I am not used to template and I cannot find what's wrong with this code :
>>>
>>> Compiler(MSVS 7) complains at line :
>>>class iterator : public std::iterator<...

>>
>>Have you tried adding #include <iterator> ? Just a guess...
>>
>>
>>>[...]


Then you should probably read the FAQ 5.8...
 
Reply With Quote
 
Old Wolf
Guest
Posts: n/a
 
      11-30-2004
"Vince" <(E-Mail Removed)> wrote:

> I am not used to template and I cannot find what's wrong with this code :
>
> Compiler(MSVS 7) complains at line :
> class iterator : public std::iterator<...
>
> Here is the source code
>
> using namespace std;


How about not calling your class 'iterator' when there is
already a class called 'iterator' in scope?

Alternatively, drop the "using namespace std;" line. It's
generally a bad idea to have that line in a header file anyway
because it forces everyone who uses your header to also have
std included, and they may not want to.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
iterating over a list as if it were a circular list Sven Python 3 03-08-2013 05:59 PM
iterating over a list as if it were a circular list Sven Python 1 03-07-2013 01:37 PM
Re: iterating over a list as if it were a circular list Chris Angelico Python 0 03-07-2013 09:28 AM
Compilation error with seperate compilation C__chp C++ 4 02-15-2008 03:57 PM
Semi-circular definitions (plus circular references) Kiuhnm C++ 16 01-03-2005 03:49 AM



Advertisments