默认参数问题
#include <iostream>struct Candybar
{
char name;
double weight;
int reliang;
};
void setcd(Candybar &a,char *d="Defu", const double b = 2.85 , const int c = 350);
int main()
{
Candybar g;
setcd(g);
std::cout << g.name;
return 0;
}
void stecd (Candybar &a ,char *d,const double b,const int c)
{
int e = 0;
while (d != '\0')
{
a.name= d;
e++;
}//对name赋值
a.weight = b;
a.reliang = c;
std::cout << a.name << std::endl;
std::cout << a.weight << std::endl;
std::cout << a.reliang << std::endl;
}
可以编译,运行错误 void setcd (Candybar &a ,char *d,const double b,const int c)
{
int e = 0;
while (d != '\0')
{
a.name= d;
e++;
}//对name赋值
a.weight = b;
a.reliang = c;
std::cout << a.name << std::endl;
std::cout << a.weight << std::endl;
std::cout << a.reliang << std::endl;
} ba21 发表于 2018-3-30 22:45
void setcd (Candybar &a ,char *d,const double b,const int c)
{
int e = 0;
??
页:
[1]