亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

no matching function for call to)為什么?

no matching function for call to)為什么?

C++
狐的傳說 2023-04-02 16:12:33
include <iostream>#include <cstring>using namespace std;class Date{ int year; int month; int day;public: int Getyear() { return year; } int Getmonth() { return month; } int Getday() { return day; } void Setyear() { }};class Product{ char *name; double price; Date deptime; char *factory; bool easy_break; Date valtime; char *color; double num;public: Product(char *n); Product(char *n,double p=0); Product(char *n,double p,Date d); void SetProduct(char *n,double p,Date d,char *f,bool e,Date v,char *c,int number); void output ();};void Product::output (){ cout<<name<<" "<<price<<endl; cout<<deptime.Getyear()<<"-"<<deptime.Getmonth()<<"-"<<deptime.Getday()<<endl; cout<<factory<<" "<<easy_break<<endl; cout<<valtime.Getyear()<<"-"<<valtime.Getmonth()<<"-"<<valtime.Getday()<<endl;}Product::Product(char *n){ name=new char[strlen(n)+1]; strcpy(name,n); cout<<"Constrcting One...."<<endl;}Product::Product(char *n,double p){ name=n; price=p; cout<<"Constrcting Two...."<<endl;}Product::Product(char *n,double p,Date d){ name=n; price=p; Date deptime(d); cout<<"Constrcting Three...."<<endl;}void Product::SetProduct(char *n,double p,Date d,char *f,bool e,Date v,char *c,int number){ name=n; price=p; Date deptime(d); // factory=f; easy_break=e; Date valtime(v); color=c; num=number;}int main(){ char s[10]; cin>>s; Product p1("car"); Product p2("glass",3.00); Product p3("pen",5.00,2009,3,14); p1.SetProduct("car",100000.0,2009,3,14,"nanjing",0,2010,10,14,"red",1.5); p1.output(); p2.output(); p3.output(); return 0;}
查看完整描述

2 回答

?
慕容森

TA貢獻1853條經驗 獲得超18個贊

問題1:
聲明:
Product(char *n);
Product(char *n, double p=0);
調用:
Product p1("car");
存在二義性錯誤,編譯器不知道究竟該調用上面兩個構造函數中的哪一個。
問題2:
聲明:
Product(char *n);
調用:
Product p1("car");
聲明是char*而調用傳遞的卻是字符串字面值,不符合C++標準,應將聲明改為Product(const char *n);
問題3:

聲明:
Product(char *n);
Product(char *n, double p=0);
Product(char *n, double p, Date d);
調用:
Product p3("pen", 5.00, 2009, 3, 14);
Product類沒有接受5個參數的構造函數。

查看完整回答
反對 回復 2023-04-05
?
DIEA

TA貢獻1820條經驗 獲得超2個贊

沒有找到你想引用的方法,請仔細檢查 你所調用的 方法名稱 是否與 原方法名稱一致,要一模一樣,不然的話,就會出現匹配不到的情況。

查看完整回答
反對 回復 2023-04-05
  • 2 回答
  • 0 關注
  • 248 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號