资源描述:
《【例2.12】重载函数应用举例[1]》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、重载函数应用举例#includeintadd(intx,inty){intsum;sum=x+y;returnsum;}intadd(intx,inty,intz){intsum;sum=x+y+z;returnsum;}voidmain(){inta,b;a=add(5,10);b=add(5,10,20);cout<<”a=”<#includeclassStud
2、ent{public:Student(char*pName="noname",intssId=0){strncpy(name,pName,40);name[39]=' ';id=ssId;cout<<"Constructingnewstudent"<3、ng"<4、;}//主函数调用结束时,先析构对象wang,再析构对象randy程序的运行结果为:ConstructingnewstudentRandyConstructingnewstudentwangCallingfn()ConstructingcopyofRandyInfunctionfn()DestructingcopyofRandyReturnedfromfn()DestructingwangDestructingRandy缺省构造函数#include#includeusingnamespacestd;classStudent{pub
5、lic:Student(char*pName){cout<<"calloneparameterconstructor"<