8.2
#include <iostream> #include <string> using namespace std; struct CandyBar{ char *name; double weight; int kaluli; }; void set(CandyBar &cb,char *name="Millennium Munch",double weight=2.85,int kaluli=350);//默认初始化 void show(const CandyBar &cb); void main82() { CandyBar c1,c2; set(c1,"DEFU",20.5,800); set(c2); system("pause"); } void set(CandyBar &cb,char *name,double weight,int kaluli) { int size=sizeof(name); cb.name=new char(size+1); strcpy(cb.name,name); cb.weight=weight; cb.kaluli=kaluli; show(cb); } void show(const CandyBar &cb) { cout<<"name:"<<cb.name<<"\nweight:"<<cb.weight <<"\nkaluli:"<<cb.kaluli<<endl; cout<<"show end!"<<endl<<endl; }
——————————————————————————————————————————————————
//写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:https://www.royalchen.com/
author:royalchen
Email:royalchen@royalchen.com
———————————————————————————————————————————————————