我有一個方法,我需要重載它,但我努力,我得到錯誤,說:no matching function for call to Vehicle_Renting::Order::Order()
C++方法重載
下面是它的外觀:
類聲明:
class Order
{
private:
class ImplementationOrder;
ImplementationOrder* implOrder;
內部類:
class Order::ImplementationOrder
{
private:
string date;
int price, id;
friend class Order;
bool isVerified;
vector<Vehicle> orderedVehicles;
Customer* customer;
friend class Order;
};
構造函數:
Order::Order(int price)
:implOrder(new ImplementationOrder())
{
#ifdef DEBUG
clog << DEBUG_PREFIX "Constructor (1 arg) called!" << endl;
#endif // DEBUG
setDate();
setPrice(price);
assert(price >= 0);
}
// copy constructor---------------------------------------------------------
Order::Order(const Order &other)
: implOrder(new ImplementationOrder(*(other.implOrder)))
{
}
方法:
void addOrder(const Order& o, const Client& c);
void addOrder(const Client& c);
void Auto_Rent::addOrder(const Order& o, const Customer& c)
{
addCustomer(c);
int pos = getCustomerPosition(c);
Order o1(o);
o1.setCustomer(implAuto_Rent->customers[pos]);
implAuto_Rent->orders.push_back(o1);
}
void Auto_Rent::addOrder(const Customer& c)
{
addCustomer(c);
int pos = getCustomerPosition(c);
Order o1;
o1.setCustomer(implAuto_Rent->customers[pos]);
implAuto_Rent->orders.push_back(o1);
}
創建對象調用的客戶:
Customer c5("Agriosas", "Lasiokas", 1994), c6("Edves", "Lasas", 1992), c7("MAtkes", "brolis", 1991);
我呼籲addOrder功能:
s.addOrder(c5);
s.addOrder(c7);
s.addOrder(c6);
代碼在哪裏調用了這些函數? – 2014-12-19 00:44:45
請顯示'Order'的類聲明。至少這是有問題的代碼!很可能你根本沒有爲'Order'類提供的默認構造函數。 – 2014-12-19 00:46:58
錯過了產生錯誤的行,錯過了該ctor的假定聲明,錯過了它的定義。我們基本上得出了和編譯器相同的結論:如果你想要一個可用的可執行文件,請顯示一些源代碼。 – MSalters 2014-12-19 00:57:50