Hi, I recently upgraded my compiler to a version that's a lot more touchy
about code not conforming to the ISO standard. Right now I am in the process
of compiling my old programs with the new compiler. The compiler complains
about a missing semi-colon in a template class and I don't see the error. I
must admit I am very weak in the area of templates but I think the program
compiled with the older version, can't say for sure, though.
Here's the code:
#ifndef LIST_HPP
#define LIST_HPP
#include <cstddef> /* NULL, size_t */
#include <stdexcept>
template<class Type>
class List
{
public:
List();
virtual ~List();
void insert(const Type& T);
void append(const Type& T);
void remove_first();
void remove_last();
void clear();
std::size_t size() const
{
return m_size;
}
bool is_empty() const
{
return m_size == 0;
}
private:
class Node;
public:
class Iterator
{
friend class List<Type>;
public:
Iterator()
:
m_node(NULL)
{
; /* Do nothing. */
}
Iterator(Node* node)
:
m_node(node)
{
; /* Do nothing. */
}
Iterator& operator++();
Iterator& operator--();
Iterator operator++(int);
Iterator operator--(int);
const Type& operator*() const;
bool operator==(const List<Type>::Iterator& rhs) const;
bool operator!=(const List<Type>::Iterator& rhs) const;
private:
Node* m_node;
};
List<Type>::Iterator begin() const;
List<Type>::Iterator end() const;
private:
class Node
{
friend class List<Type>;
friend class Iterator;
public:
Node()
:
m_next(NULL),
m_previous(NULL)
{
; /* Do nothing. */
}
Node(const Type& T)
:
Item(T),
m_next(NULL),
m_previous(NULL)
{
; /* Do nothing. */
}
private:
Type Item;
Node* m_next;
Node* m_previous;
};
Node* m_header;
Node* m_tail;
std::size_t m_size;
};
The compiler chokes on the following line:
List<Type>::Iterator begin() const;
the error message is:
error: expected `;' before "begin"
What is wrong?
/ WP