c++primer P40的例子为什么编译通不过?
-------------Array.h-------------
template <class elemType>
class Array{
public:
explicit Array(int size=DefaultArraySize);
Array(elemType *array,int array_size);
Array(const Array &rhs);
virtual ~Array(){ delete [] ia;}
bool operator==(const Array&)const;
bool operator!=(const Array&)const;
Array& operator=(const Array&);
int size() const {return _size;}
virtual elemType& operator[](int index){return ia[index];}
virtual void sort();
virtual elemType min() const;
virtual elemType max() const;
virtual int find(const elemType &value)const;
protected:
static const int DefaultArraySize = 12;
int _size;
elemType *ia;
};
----------------4.cpp-----------------
#include <iostream>
#include "Array.h"
using namespace std;
int main()
{
const int array_size=4;
Array<int> ia(array_size);
Array<double> da(array_size);
Array<char> ca(array_size);
int ix;
for (ix=0;ix<array_size;++ix)
{
ia[ix]=ix;
da[ix]=ix*1.75;
ca[ix]=ix+'a';
}
for (ix=0;ix<array_size;++ix)
cout<<"[ "<<ix<<" ] ia: "<<ia[ix]
<<"\tca: "<<ca[ix]
<<"\tda: "<<da[ix]<<endl;
return 0;
}
VC6下编译时出现错误:
--------------------Configuration: 4 - Win32 Debug--------------------
Compiling...
4.cpp
e:\vc程序\c++\4\array.h(24) : error C2258: illegal pure syntax, must be '= 0'
e:\vc程序\c++\4\array.h(28) : see reference to class template instantiation 'Array<elemType>' being compiled
e:\vc程序\c++\4\array.h(24) : error C2252: 'DefaultArraySize' : pure specifier can only be specified for functions
e:\vc程序\c++\4\array.h(28) : see reference to class template instantiation 'Array<elemType>' being compiled
e:\vc程序\c++\4\array.h(24) : error C2258: illegal pure syntax, must be '= 0'
e:\vc程序\c++\4\4.cpp(8) : see reference to class template instantiation 'Array<int>' being compiled
e:\vc程序\c++\4\array.h(24) : error C2252: 'DefaultArraySize' : pure specifier can only be specified for functions
e:\vc程序\c++\4\4.cpp(8) : see reference to class template instantiation 'Array<int>' being compiled
e:\vc程序\c++\4\array.h(24) : error C2258: illegal pure syntax, must be '= 0'
e:\vc程序\c++\4\4.cpp(9) : see reference to class template instantiation 'Array<double>' being compiled
e:\vc程序\c++\4\array.h(24) : error C2252: 'DefaultArraySize' : pure specifier can only be specified for functions
e:\vc程序\c++\4\4.cpp(9) : see reference to class template instantiation 'Array<double>' being compiled
e:\vc程序\c++\4\array.h(24) : error C2258: illegal pure syntax, must be '= 0'
e:\vc程序\c++\4\4.cpp(10) : see reference to class template instantiation 'Array<char>' being compiled
e:\vc程序\c++\4\array.h(24) : error C2252: 'DefaultArraySize' : pure specifier can only be specified for functions
e:\vc程序\c++\4\4.cpp(10) : see reference to class template instantiation 'Array<char>' being compiled
Error executing cl.exe.
4.exe - 8 error(s), 0 warning(s)
请指点,谢谢!