我仍然是继承和多态的新手,所以请原谅我。我正在使用Linux中的Scite编辑器编写一组派生类,并且收到编译错误,指出我的值构造函数实现与头文件中的原型不匹配。
powerseller.cpp:9:1:错误:\ u2018PowerSeller :: PowerSeller的原型(std :: string,std :: string,std :: string,std :: string,std :: string,std :: string,std :: string,std :: string,std :: string,std :: string)\ u2019与类中的任何一个都不匹配\ u2018PowerSeller \ u2019 powerseller.h:15:3:错误:候选人是:PowerSeller :: PowerSeller(const PowerSeller&) powerseller.h:13:3:错误:PowerSeller :: PowerSeller(std :: string,std :: string) powerseller.cpp:7:1:错误:PowerSeller :: PowerSeller()
这是我的头文件。值构造函数是抛出错误的那个。
#include "seller.h"
#ifndef POWERSELLER_H
#define POWERSELLER_H
using namespace std;
class PowerSeller : public Seller
{
public:
//constructors & destructors
PowerSeller();
PowerSeller(string fName, string lName, string id, string email, string loc, string date, string numOfStars, string numOfItems, string webAddress, string yearItems);
PowerSeller(const PowerSeller& other);
~PowerSeller();
//member functions
void setWebsite(string webAddress);
void setYearItems(string yearItems);
virtual void print();
virtual void read();
//overloaded operators
bool operator ==(const PowerSeller& rhs);
PowerSeller & operator =(const PowerSeller& rhs);
//overloaded ostream
friend ostream & operator <<(ostream& os, const PowerSeller& rhs);
protected:
string website, items;
};
#endif
这是实施
include "powerseller.h"
#include <iostream>
using namespace std;
PowerSeller::PowerSeller(){}
PowerSeller::PowerSeller(string fName, string lName, string id, string email, string loc, string date, string numOfStars, string numOfItems, string webAddress, string yearItems): Seller(fName, lName, id, email, loc, date, numOfStars, numOfItems){
website = webAddress;
items = yearItems;
}
PowerSeller::PowerSeller(const PowerSeller& other):Seller(other){
website= other.website;
items = other.items;
}
PowerSeller::~PowerSeller(){
website = " ";
items = " ";
}
我的最终问题是:为什么编译器仍然显示当我在文件中更改它以匹配实现时,PowerSeller的值构造函数只接受两个字符串参数?