I'm adding a function to a template class which returns a type that is defined by the class. Now the function is getting a little long so I want to declare it in the class declaration but define it outside. Here is what I'm talking about
Code:
//here is where the type is defined
template <class T> class Vec {
public:
typedef T* iterator;
typedef const T* const_iterator;
...
other member functions that return iterators are defined and declared at the same time like this...
Code:
iterator begin() { return data; }
...
const_iterator end() const { return avail; }
and here is the function declaration and definition I created for this class
Code:
//declared within the class scope
const_iterator end() const { return avail; }
...
//defined outside the scope, but in same header file of course
template <class T>
iterator Vec<T>::erase(const T que)
{
iterator result = std::find(data, avail, que);
alloc.destroy(result);
if (result == avail && avail == limit)
{
avail = limit = avail - 1;
}
if (result == avail && avail != limit)
avail --;
else
{
iterator before = result;
result++;
std::copy(result, avail, before);
avail--;
}
return result;
}
But I'm getting the error
Code:
Vec.h:142: error: expected constructor, destructor, or type conversion before "Vec"
Vec.h:142: error: expected `;' before "Vec"
both errors highlight "iterator Vec<T>::erase(const T que)"
now of course when I change iterator to T* it eliminates errors. Is there a workaround so that I can put user defined types in the header outside of the class scope, or is that just hte way it is?