我遇到了几个错误,[E1]“C++ 需要所有声明的类型说明符”、[E2]“使用未声明的标识符”和 [E3]“需要一个类名或命名空间”。
#ifndef MAIN_SAVITCH_SEQUENCE_H
#define MAIN_SAVITCH_SEQUENCE_H
template <class T>
class sequence
{
public:
// TYPEDEFS and MEMBER CONSTANTS
typedef T value_type;
static const int CAPACITY = 30;
// CONSTRUCTOR
sequence( );
// MEMBER FUNCTIONS
void showSequence();
void attach(value_type entry);
value_type current( );
void remove_current( );
int size( );
private:
value_type data[CAPACITY];
int used;
};
template <class T>
[E3] sequence::sequence( )
{
[E2] used = 0;
}
template <class value_type>
[E3] void sequence::attach(value_type entry)
{
data[used++] = entry;
}
sequence::value_type sequence::current( )
//replace sequence::value_type with typename value_type for your template
{
return data[used-1];
}
void sequence::remove_current( )
{
used--;
}
int sequence::size( )
{
return used;
}
void sequence::showSequence()
{
std::string display = "";
for (int i = 0; i<used; i++)
std::cout << data[i] << "\n";
}
#endif