#include <vector>
#include <iterator>
#include <algorithm>
#include <exception>
#ifndef __LIST_HPP_INCLUDED
#define __LIST_HPP_INCLUDED
class list_error: public std::exception
{
public:
virtualconstchar* what() constthrow()
{
return errstr;
}
protected:
constchar* errstr = "";
};
class list_notfound: public list_error
{
protected:
constchar* errstr = "The specified element could not be found";
};
template <typename T>
class list
{
public:
list() {};
~list() {}
list operator=(T rhs[])
{
vect.insert(vect.being(), rhs, sizeof(rhs)); return *this;
}
void append(T item)
{
vect.push_back(item);
}
void insert(int position, T item)
{
vect.insert(vect.begin() + position, item);
}
int count(T item)
{
int total = 0;
for (iter = vect.begin(); iter != vect.end(); ++iter)
{
if (*iter == item)
{
total++;
}
}
return total;
}
void reverse()
{
std::reverse(vect.begin(), vect.end());
}
T pop(int element=-1)
{
int pos;
if (element == -1)
{
pos = vect.size() - 1;
}
else
{
pos = element;
}
T &ret = vect.at(pos);
vect.erase(vect.begin()+pos);
return ret;
}
int index(T item)
{
for (iter = vect.begin(); iter != vect.end(); ++iter)
{
if (*iter == item)
{
return *iter;
}
}
throw list_notfound;
}
private:
std::vector<T> vect;
typename std::vector<T>::const_iterator iter;
};
#endif
And GCC is giving me this error:
1 2
C:\C++\include/list.hpp: In member function 'int list<T>::index(T)':
C:\C++\include/list.hpp:84:22: error: expected primary-expression before ';' token