C++中什么叫做没有定义的函数?
#include<iostream>usingnamespacestd;classvehicl{private:char*vname;intvnumber;public:...
#include <iostream>
using namespace std;
class vehicl
{
private:
char *vname;
int vnumber;
public:
vehicl(char *vname,int _vnumber)
{
vname=new char[strlen(vname)+1];
strcpy(vname,vname);
vnumber=_vnumber;
}
virtual void print()
{
cout<<"Vname:"<< vname <<'\t'<<"Vnumber:"<< vnumber <<endl;
}
virtual ~vehicl()
{
delete []vname;
}
};
class car:public vehicl
{
private:
char *cname;
int cnumber;
public:
car(vehicl &t,char *cname,int _cnumber):vehicl(t)
{
cname=new char[strlen(cname)+1];
strcpy(cname,cname);
cnumber=_cnumber;
}
void print()
{
vehicl::print();
cout<<"Cname:"<< cname <<'\t'<<"Cnumber:"<< cnumber <<endl;
}
~car()
{
delete []cname;
}
};
class truck:public vehicl
{
private:
char *tname;
int tnumber;
public:
truck(vehicl &t,char *tname,int _tnumber):vehicl(t)
{
tname=new char[strlen(tname)+1];
strcpy(tname,tname);
tnumber=_tnumber;
}
void print()
{
vehicl::print();
cout<<"Tname:"<< tname <<'\t'<<"Number:"<< tnumber <<endl;
}
~truck()
{
delete []tname;
}
};
class boat:public vehicl
{
private:
char *bname;
int bnumber;
public:
boat(vehicl &t,char *bname,int _bnumber):vehicl(t)
{
bname=new char[strlen(bname)+1];
strcpy(bname,bname);
bnumber=_bnumber;
}
void print()
{
vehicl::print();
cout<<"Bname:"<< bname <<'\t'<<"Number:"<< bnumber <<endl;
}
~boat()
{
delete []bname;
}
};
void fun(vehicl &t)
{
t.print();
}
int main()
{
vehicl v1("路虎",1);
car c1("卡车拉货",1);
truck t1("保时捷",1);
boat b1("兰博基尼",1);
fun(v1);
fun(c1);
fun(t1);
fun(b1);
return 0;
}错误提示:[Error] C:\Users\hp\Documents\C-Free\Temp\未命名20.cpp:103: error: no matching function for call to `boat::boat(const char[9], int)' 展开
using namespace std;
class vehicl
{
private:
char *vname;
int vnumber;
public:
vehicl(char *vname,int _vnumber)
{
vname=new char[strlen(vname)+1];
strcpy(vname,vname);
vnumber=_vnumber;
}
virtual void print()
{
cout<<"Vname:"<< vname <<'\t'<<"Vnumber:"<< vnumber <<endl;
}
virtual ~vehicl()
{
delete []vname;
}
};
class car:public vehicl
{
private:
char *cname;
int cnumber;
public:
car(vehicl &t,char *cname,int _cnumber):vehicl(t)
{
cname=new char[strlen(cname)+1];
strcpy(cname,cname);
cnumber=_cnumber;
}
void print()
{
vehicl::print();
cout<<"Cname:"<< cname <<'\t'<<"Cnumber:"<< cnumber <<endl;
}
~car()
{
delete []cname;
}
};
class truck:public vehicl
{
private:
char *tname;
int tnumber;
public:
truck(vehicl &t,char *tname,int _tnumber):vehicl(t)
{
tname=new char[strlen(tname)+1];
strcpy(tname,tname);
tnumber=_tnumber;
}
void print()
{
vehicl::print();
cout<<"Tname:"<< tname <<'\t'<<"Number:"<< tnumber <<endl;
}
~truck()
{
delete []tname;
}
};
class boat:public vehicl
{
private:
char *bname;
int bnumber;
public:
boat(vehicl &t,char *bname,int _bnumber):vehicl(t)
{
bname=new char[strlen(bname)+1];
strcpy(bname,bname);
bnumber=_bnumber;
}
void print()
{
vehicl::print();
cout<<"Bname:"<< bname <<'\t'<<"Number:"<< bnumber <<endl;
}
~boat()
{
delete []bname;
}
};
void fun(vehicl &t)
{
t.print();
}
int main()
{
vehicl v1("路虎",1);
car c1("卡车拉货",1);
truck t1("保时捷",1);
boat b1("兰博基尼",1);
fun(v1);
fun(c1);
fun(t1);
fun(b1);
return 0;
}错误提示:[Error] C:\Users\hp\Documents\C-Free\Temp\未命名20.cpp:103: error: no matching function for call to `boat::boat(const char[9], int)' 展开
展开全部
boat(vehicl &t,char *bname,int _bnumber):vehicl(t)
前文代码中定义的boat类构造函数有三个参数vehicl &t,char *bname,int _bnumber;
但是后面实例化的时候只传入了两个参数,所以编译器找不到两个参数的构造函数:
boat b1("兰博基尼",1);
前文代码中定义的boat类构造函数有三个参数vehicl &t,char *bname,int _bnumber;
但是后面实例化的时候只传入了两个参数,所以编译器找不到两个参数的构造函数:
boat b1("兰博基尼",1);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2019-06-07
展开全部
给你一个例子:
#include <iostream>
using namespace std;
void example(void) // 一个没有定义的函数
{}
int main()
{
example(); // 由于example函数没有定义,所以这一行什么都不做
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询