我不明白。我一直盯着代码看代码三个小时,我看不出问题。
我正在创建的名为 TwoDayPackage 的类派生自一个名为 Package 的类。
这就是我定义构造函数的方式:
TwoDayPackage(string, string, string, string, int, string, string, string, string, int, float, float, float);
这是我实现构造函数的方式:
TwoDayPackage::TwoDayPackage(string sName, string sAddress, string sState, string sCountry, int sZIP, string rName, string rAddress, string rState, string rCountry, int rZIP, float weight, float cost, float flat)
{
Package::Package(sName, sAddress, sState, sCountry, sZIP, rName, rAddress, rState, rCountry, rZIP, weight, cost);
flatRate = flat;
}
这就是我在主要功能中使用它的方式。
TwoDayPackage pack2(senderName, senderAddress, senderState, senderCountry, senderZIP, receipientName, receipientAddress, receipientState, receipientCountry, receipientZIP, weight, cost, flat);
我知道我的参数列表很长,这是有原因的。 谢谢。
最佳答案
应该使用:
TwoDayPackage::TwoDayPackage(string sName, string sAddress, string sState, string sCountry, int sZIP, string rName, string rAddress, string rState, string rCountry, int rZIP, float weight, float cost, float flat)
:Package(sName, sAddress, sState, sCountry, sZIP, rName, rAddress, rState, rCountry, rZIP, weight, cost)
{
flatRate = flat;
}
关于c++ - Visual C++ 中的 "No appropriate default constructor available"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/710432/