尝试编译以下类时出现错误
Stack.cpp:28:错误:'::' 标记之前的预期构造函数、析构函数或类型转换
#include <iostream>
using namespace std;
template <class T>
class Stack
{
public:
Stack(): head(NULL) {};
~Stack();
void push(T *);
T* pop();
protected:
class Element {
public:
Element(Element * next_, T * data_):next(next_), data(data_) {}
Element * getNext() const { return next; }
T * value() const {return data;}
private:
Element * next;
T * data;
};
Element * head;
};
Stack::~Stack()
{
while(head)
{
Element * next = head->getNext();
delete head;
head = next;
}
}