B
Barry Hynes
Hi Folks,
why does the following code give me parse errors,
What i am trying to do is create an operator= for safelist.
keep getting parse errors when i try and use the iterators in list<T>.
any help greatly appreciated
#ifndef SAFELIST_H
#define SAFELIST_H
using namespace std;
#include <list>
#include <iterator>
#include <memory>
#include <stdexcept>
template<typename T>
class SafeList : private list<T> {
public:
using list<T>:ush_front;
using list<T>::size;
using list<T>::insert;
using list<T>::begin;
using list<T>::end;
//using list<T>::const_iterator;
//using list<T>::iterator;
//constructors
SafeList() : list<T>(){}//No no-arg ctor
SafeList(const T* first, const T* last) : list<T>(){
insert(begin(), *first, *last);
}
SafeList(const SafeList<T>& x) : list<T>(){
insert(begin(), x.begin(), x.end());
}
//destructor
~SafeList(){
erase(begin(), end());
}
//assignment
SafeList<T>& operator=(const SafeList<T>& x){
if(this != &x){
list<T>::iterator f1; //error
f1 = begin();
list<T>::const_iterator l1 //error
l1 = end();
list<T>::const_iterator f2 //error
f2 = x.begin();
list<T>::const_iterator l2 //error
l2 = x.end();
while(f1 != l1 && f2 != l2)
*f1++ = *f2++;
if (f2 == l2)
erase(f1, l1);
else
insert(l1, f2, l2);
}
return *this;
}
............
why does the following code give me parse errors,
What i am trying to do is create an operator= for safelist.
keep getting parse errors when i try and use the iterators in list<T>.
any help greatly appreciated
#ifndef SAFELIST_H
#define SAFELIST_H
using namespace std;
#include <list>
#include <iterator>
#include <memory>
#include <stdexcept>
template<typename T>
class SafeList : private list<T> {
public:
using list<T>:ush_front;
using list<T>::size;
using list<T>::insert;
using list<T>::begin;
using list<T>::end;
//using list<T>::const_iterator;
//using list<T>::iterator;
//constructors
SafeList() : list<T>(){}//No no-arg ctor
SafeList(const T* first, const T* last) : list<T>(){
insert(begin(), *first, *last);
}
SafeList(const SafeList<T>& x) : list<T>(){
insert(begin(), x.begin(), x.end());
}
//destructor
~SafeList(){
erase(begin(), end());
}
//assignment
SafeList<T>& operator=(const SafeList<T>& x){
if(this != &x){
list<T>::iterator f1; //error
f1 = begin();
list<T>::const_iterator l1 //error
l1 = end();
list<T>::const_iterator f2 //error
f2 = x.begin();
list<T>::const_iterator l2 //error
l2 = x.end();
while(f1 != l1 && f2 != l2)
*f1++ = *f2++;
if (f2 == l2)
erase(f1, l1);
else
insert(l1, f2, l2);
}
return *this;
}
............