【报错】no appropriate default constructor available,该如何处理
【报错】no appropriate default constructor available
楼主在做一个叫做hypermarket project时,想利用Linked list储存产品信息,
于是写了以下3个文件:listbase.h listLL.h listLL.cpp
但是却碰上如题的报错信息,在listLL.h中我已经写有struct 构造器,
为什么在visual studio 2010 Ultimate编译后程序仍然说我没有可用的构造器?
真心请大神指教。
#ifndef LISTBASE_H_
#define LISTBASE_H_
#include <iostream>
#include <string>
#include "Product.h"
using namespace std;
class ListBase
{
public:
ListBase()
{
_size=0;
}
~ListBase();
bool isEmpty()
{
return (_size==0);
}
int getProductAmount()
{
return _size;
}
virtual bool insert(Product newItem)=0;
virtual bool remove(string name)=0;
virtual bool retrieve(string name)=0;
virtual string displayList()=0;
virtual int retrieveIndex(string name)=0;
protected:
int _size;
};
#endif
--------------------------------------------------listbase.h
#ifndef LISTLL_H_
#define LISTLL_H_
#include <string>
#include <iostream>
#include "ListBase.h"
using namespace std;
class ListLL:public ListBase
{
private:
struct ListNode
{
Product item;
ListNode *next;
};
ListNode *_head;
//ListNode *traverseTo(int index);
public:
ListLL();
~ListLL();
bool insert(Product newItem);
bool remove(string name);
bool retrieve(string name);
int retrieveIndex(string name);
bool retrieveType(string category);
bool retrieveComp(string company);
Product bestSellingProduct(string category);//find the best selling product in one given category
string bestSellingComp();//find the best selling manufacturer
string topSellingProducts(int num);//find the TOP X selling products
string displayList();//list all products
};
#endif
------------------------------------------ListLL.h
#include <string>
#include <iostream>
#include "ListLL.h"
using namespace std;
bool ListLL::remove(string name)
{
ListNode *cur,*prev;
int index;
if(isEmpty())
{
return false;
}
prev=_head;
index=retrieveIndex(name);
for(int i=0;i<index;i++)
{
prev=prev->next;
}//find the previous node
cur=prev->next;
prev->next=cur->next;
delete cur;
}
int ListLL::retrieveIndex(string name)
{
ListNode *ptr;
int i;
if(isEmpty())
{
return 0;
}
ptr=_head;
for(i=0;i<_size;i++)
{
if(ptr->item.getName()==name)//if the product has been found
{
cout<<ptr->item.getName()<<endl;
return i;
}
ptr=ptr->next;
}
return 0;
}
bool ListLL::retrieve(string name)
{
ListNode *ptr;
if(isEmpty())
{
return false;
}
ptr=_head;
for(int i=0;i<_size;i++)
{
if(ptr->item.getName()==name)//if the product has been found
{
cout<<ptr->item.getName()<<endl;
return true;
}
ptr=ptr->next;
}
return false;
}
bool ListLL::insert(Product newItem)
{
if(isEmpty())
{
_head=NULL;
}
//if the linked list is empty, we initialize the _head as null
ListNode *newPtr=new ListNode;
newPtr->item=newItem;
newPtr->next=_head;
_head=newPtr;
//add newItem to the linked list
_size=getProductAmount()+1;
楼主在做一个叫做hypermarket project时,想利用Linked list储存产品信息,
于是写了以下3个文件:listbase.h listLL.h listLL.cpp
但是却碰上如题的报错信息,在listLL.h中我已经写有struct 构造器,
为什么在visual studio 2010 Ultimate编译后程序仍然说我没有可用的构造器?
真心请大神指教。
#ifndef LISTBASE_H_
#define LISTBASE_H_
#include <iostream>
#include <string>
#include "Product.h"
using namespace std;
class ListBase
{
public:
ListBase()
{
_size=0;
}
~ListBase();
bool isEmpty()
{
return (_size==0);
}
int getProductAmount()
{
return _size;
}
virtual bool insert(Product newItem)=0;
virtual bool remove(string name)=0;
virtual bool retrieve(string name)=0;
virtual string displayList()=0;
virtual int retrieveIndex(string name)=0;
protected:
int _size;
};
#endif
--------------------------------------------------listbase.h
#ifndef LISTLL_H_
#define LISTLL_H_
#include <string>
#include <iostream>
#include "ListBase.h"
using namespace std;
class ListLL:public ListBase
{
private:
struct ListNode
{
Product item;
ListNode *next;
};
ListNode *_head;
//ListNode *traverseTo(int index);
public:
ListLL();
~ListLL();
bool insert(Product newItem);
bool remove(string name);
bool retrieve(string name);
int retrieveIndex(string name);
bool retrieveType(string category);
bool retrieveComp(string company);
Product bestSellingProduct(string category);//find the best selling product in one given category
string bestSellingComp();//find the best selling manufacturer
string topSellingProducts(int num);//find the TOP X selling products
string displayList();//list all products
};
#endif
------------------------------------------ListLL.h
#include <string>
#include <iostream>
#include "ListLL.h"
using namespace std;
bool ListLL::remove(string name)
{
ListNode *cur,*prev;
int index;
if(isEmpty())
{
return false;
}
prev=_head;
index=retrieveIndex(name);
for(int i=0;i<index;i++)
{
prev=prev->next;
}//find the previous node
cur=prev->next;
prev->next=cur->next;
delete cur;
}
int ListLL::retrieveIndex(string name)
{
ListNode *ptr;
int i;
if(isEmpty())
{
return 0;
}
ptr=_head;
for(i=0;i<_size;i++)
{
if(ptr->item.getName()==name)//if the product has been found
{
cout<<ptr->item.getName()<<endl;
return i;
}
ptr=ptr->next;
}
return 0;
}
bool ListLL::retrieve(string name)
{
ListNode *ptr;
if(isEmpty())
{
return false;
}
ptr=_head;
for(int i=0;i<_size;i++)
{
if(ptr->item.getName()==name)//if the product has been found
{
cout<<ptr->item.getName()<<endl;
return true;
}
ptr=ptr->next;
}
return false;
}
bool ListLL::insert(Product newItem)
{
if(isEmpty())
{
_head=NULL;
}
//if the linked list is empty, we initialize the _head as null
ListNode *newPtr=new ListNode;
newPtr->item=newItem;
newPtr->next=_head;
_head=newPtr;
//add newItem to the linked list
_size=getProductAmount()+1;