Visual Studio 2005 is giving me heartburn while working with templates. Does anybody know what is going on with the following code, and the errors below? It says there is a syntax error, but I cannot find it.
#ifndef DEQUEUE_H
#define DEQUEUE_H
#include <iostream>
#include <list>
template<class Item>
class Dequeue
{
private:
list<Item> l;
public:
Dequeue();
~Dequeue();
Item removeFront();
Item removeBack();
Item peekFront();
Item peekBack();
void addFront(const Item& value);
void addBack(const Item& value);
void clear();
bool isEmpty() const;
int getSize() const;
};
template <class Item>
Dequeue<Item>::Dequeue()
{
}
template <class Item>
Dequeue<Item>::~Dequeue()
{
l.~list<Item>();
}
template <class Item>
void Dequeue<Item>::addFront(const Item& value)
{
l.push_front(value);
}
template <class Item>
void Dequeue<Item>::addBack(const Item& value)
{
l.push_back(value);
}
template <class Item>
Item Dequeue<Item>::removeFront()
{
Item result;
if (isEmpty())
{
cout << "Dequeue::removeFront(): Error! Dequeue is empty." << endl;
return -1;
}
else
{
result = l.front();
l.pop_front();
}
return result;
}
template <class Item>
Item Dequeue<Item>::removeBack()
{
Item result;
if (isEmpty())
{
cout << "Dequeue::removeBack(): Error! Dequeue is empty." << endl;
return -1;
}
else
{
result = l.front();
l.pop_back();
}
return result;
}
template <class Item>
Item Dequeue<Item>::peekFront()
{
Item result;
if (isEmpty())
{
cout << "Dequeue::peek(): Error! Dequeue is empty." << endl;
return -1;
}
else
{
result = l.front();
}
return result;
}
template <class Item>
Item Dequeue<Item>::peekBack()
{
Item result;
if (isEmpty())
{
cout << "Dequeue::peek(): Error! Dequeue is empty." << endl;
return -1;
}
else
{
result = l.back();
}
return result;
}
template <class Item>
void Dequeue<Item>::clear()
{
return l.clear();
}
template <class Item>
bool Dequeue<Item>::isEmpty() const
{
return l.empty();
}
template <class Item>
int Dequeue<Item>::getSize() const
{
return l.size();
}
#endif
1>Compiling...
1>main.cpp
1>c:\users\philip\documents\visual studio 2005\projects\cs211\prog4c1\prog4c1\dequeue.h(11) : error C2143: syntax error : missing ';' before '<'
1> c:\users\philip\documents\visual studio 2005\projects\cs211\prog4c1\prog4c1\dequeue.h(26) : see reference to class template instantiation 'Dequeue<Item>' being compiled
1>c:\users\philip\documents\visual studio 2005\projects\cs211\prog4c1\prog4c1\dequeue.h(11) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\philip\documents\visual studio 2005\projects\cs211\prog4c1\prog4c1\dequeue.h(11) : error C2238: unexpected token(s) preceding ';'
1>Build log was saved at "file://c:\Users\Philip\Documents\Visual Studio 2005\Projects\CS211\prog4c1\prog4c1\Debug\BuildLog.htm"
1>prog4c1 - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========