I have a program I wrote for a class back in 2000 that I thought I would try to run just for the fun of it. It used to compile back in 2000, but I'm getting a bunch of errors now. I pretty much haven't looked at C++ code since that class, so I'm a bit bewildered. I resolved a bunch of complaints about iostream.h & list.h (putting "std::" in front of a bunch of things like std::cerr, etc). I don't know if that caused the current errors, or whether there's something inherently wrong with my iterators, but the only thing left to resolve involves a bunch of iterator constructors. First, here is a sample of the errors:
SolutionList.cpp:10:22: error: no matching constructor for initialization of 'PieceList::iterator'
PieceList::iterator i=rhs.first();
^ ~~~~~~~~~~~
./PieceList.h:27:5: note: candidate constructor not viable: expects an l-value for 1st argument
iterator(iterator& rhs){data = rhs.data;}
^
./PieceList.h:28:5: note: candidate constructor not viable: no known conversion from 'PieceList::iterator' to 'std::list<Piece>::iterator &'
(aka '__list_iterator<value_type, __void_pointer> &') for 1st argument
iterator(std::list<Piece>::iterator& rhs){data = rhs;}
^
./PieceList.h:26:5: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
iterator(){}
^
And here's what I believe is the relevant portion of code:
class PieceList
{
public:
PieceList(){}
PieceList(PieceList& rhs){pieces = rhs.pieces;}
PieceList(std::list<Piece>& rhs){pieces = rhs;}
friend std::ifstream& operator>>(std::ifstream&,PieceList&);
friend std::istream& operator>>(std::istream&,PieceList&);
class iterator
{
public:
friend class PieceList;
iterator(){}
iterator(iterator& rhs){data = rhs.data;}
iterator(std::list<Piece>::iterator& rhs){data = rhs;}
Piece operator*(){return *data;}
iterator& operator=(iterator& rhs){data=rhs.data;return *this;}
iterator& operator=(std::list<Piece>::iterator& rhs){data = rhs;return *this;}
bool operator==(iterator& rhs){return data==rhs.data;}
bool operator==(const iterator& rhs) const{return data==rhs.data;}
bool operator!=(iterator rhs){return data != rhs.data;}
iterator& operator++(){++data;return *this;}
iterator& operator--(){--data;return *this;}
private:
std::list<Piece>::iterator data;
};
iterator first(){iterator i;i.data=pieces.begin();return i;}
iterator last(){iterator i;i.data=pieces.end();return i;}
private:
std::list<Piece> pieces;
};
So I know that it doesn't like the second constructor, but I'm not sure how to fix it. I couldn't make sense of any of my google results from googling the errors. Can anyone point me in the right direction?