【发布时间】:2013-05-08 06:39:19
【问题描述】:
这是我的代码:
class package
{
protected:
string name;
string city;
string state;
int zip;
double weight;
double costPerOunce;
public:
package::package(string Name, string City, string State, int Zip, double Weight, double CostPerOunce):
name(Name), city(City), state(State),
zip(Zip), weight(Weight), costPerOunce(CostPerOunce)
{
}
double calculateCost()
{
return (weight * costPerOunce);
}
};
class twoDayPackage: public package
{
protected:
double flatFee;
public:
twoDayPackage::twoDayPackage(double FlatFee):
flatFee(FlatFee)
{
}
double calculateCost()
{
return (weight * costPerOunce) + flatFee;
}
};
int main()
{
system ("pause");
return 0;
}
我尝试运行这段代码,我得到的错误如下: error C2512: 'package' : 没有合适的默认构造函数可用
该错误与基类构造函数的继承有关,但我不知道代码未运行的确切原因。请帮帮我。
【问题讨论】:
-
请学习基本语法...
-
当你编写自己的构造函数时,默认的会被覆盖。
twoDayPackage::twoDayPackage(double FlatFee):会调用它,但它不存在。
标签: c++ inheritance