部落怎么潘达利亚:c++类属类编程时出现的问题

来源:百度文库 编辑:中科新闻网 时间:2024/05/11 13:51:58
const int MAX_NUM=21;

template<typename Type>
class HEAP{
private:
template<typename Type>
//content存放堆中元素的内容,可以是int,float,double;
Type* content;
int count;
public:
HEAP();
void delete_unit(int index);
void insert(Type x);
void make_heap(Type h[],int n);
void heap_sort(Type a[]);
protected:
void shift_down(int index);
void shift_up(int index);

};

HEAP<class Type>::HEAP()
{
count=0;
content=new Type[MAX_NUM];
}
--------------------Configuration: heap - Win32 Debug--------------------
Compiling...
main.cpp
f:\microsoft visual studio\myprojects\heap\heap.h(30) : error C2512: 'Type' : no appropriate default constructor available
Error executing cl.exe.

heap.exe - 1 error(s), 0 warning(s)

我写的是一个堆类属类,实在是不明白这些错误应该怎么改。
f:\microsoft visual studio\myprojects\heap\heap.h(30) : error C2512: 'Type' : no appropriate default constructor available第一个错误,我已经翻了几本书关于类属类的部分,我几乎是和它们一模一样的,还是错。

把 HEAP<class Type>::HEAP()
改为:
template< typename Type >HEAP< Type >::HEAP()