错误no appropriate default constructor available关键好像就是这一句有点问题 分不敢设多,很多都被忽视了,dataList(int sz=defaultSize):ArraySize(sz),CurrentSize(0){Element=new dataNode[sz];assert(Element!=NULL);}具体程序如

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/15 08:43:16

错误no appropriate default constructor available关键好像就是这一句有点问题 分不敢设多,很多都被忽视了,dataList(int sz=defaultSize):ArraySize(sz),CurrentSize(0){Element=new dataNode[sz];assert(Element!=NULL);}具体程序如
错误no appropriate default constructor available
关键好像就是这一句有点问题 分不敢设多,很多都被忽视了,
dataList(int sz=defaultSize):ArraySize(sz),CurrentSize(0)
{Element=new dataNode[sz];assert(Element!=NULL);}
具体程序如下:
#include "iostream.h"
#include
#include "assert.h"
#include "stdlib.h"
const int defaultSize=100;
template
class dataList;
template
class dataNode {
friend class dataList;
public:
dataNode(const K x):key(x){}
K getKey()const {return key;}
void setKey(K k){key=k;}
private:
K key;
};
template
class dataList{
public:
dataList(int sz=defaultSize):ArraySize(sz),CurrentSize(0)
{Element=new dataNode[sz];assert(Element!=NULL);}
dataList(dataList&R);
virtual dataList(){delete []Element;}
virtual int Length(){return CurrentSize;}
virtual void changeCL(int x){CurrentSize=x;}
friend istream& operator >> (istream& in,dataList&InList);
protected:
dataNode *Element;
int ArraySize,CurrentSize;
};
template
class searchList:public dataList{
public:
searchList(int sz=defaultSize):dataList(sz){}
virtual int SeqSearch(const K x)const;
int BinarySearch(const K x)const;
int IndexSearch(const K x)const;
};
template
int searchList::SeqSearch(const K x)const{
Element[CurrentSize].key=x;
int i=0;
while(Element[i].key!=x)
i++;
return i+1;
};
template
int searchList::BinarySearch(const K x)const{
int high=CurrentSize,low=0,mid;
while(lowElement[mid].key)
low=mid+1;
else if(x

错误no appropriate default constructor available关键好像就是这一句有点问题 分不敢设多,很多都被忽视了,dataList(int sz=defaultSize):ArraySize(sz),CurrentSize(0){Element=new dataNode[sz];assert(Element!=NULL);}具体程序如
常常在编译C++的时候,会出现这个问题,这儿是因为系统找不到默认的构造函数.
因为类在没有定义任何构造函数的时候,系统才会默认产生构造函数,一旦定义了任何形式的构造函数,系统就不会在产生默认的构造函数了.该错误是所找不到正确的无参数的构造函数.
所以,一般情况下,只需要写一个空的构造函数,就可以解决问题.