微信公开课小程序热门讨论「c++ 一个小程序不好用」最新回复-你的问题是数组定义越界问题,charsex[2];charage[2];只需改成charsex[4];charage[4];即可。只是我在vs2008上测试的完整代码,运行结果是你想要的那种#includeiostream#includestring.husingnamespacestd;classstudent{public:virtualvoidsname()=0;virtualvoidssex()=0;virtualvoidsage()=0;};classL_student:publicstudent{public:charname[10];charsex[4];charage[4];voiddispname(){coutnameendl;}voidsname(){dispname();}voiddispsex(){coutsexendl;}voidssex(){dispsex();}voiddispage(){coutageendl;}voidsage(){dispage();}L_student(charp[10],chary[2]){strcpy(name,p);strcpy(sex,y);strcpy(age,20);}~L_student(){coutnameendlsexendlageendl;}};voidmain(){L_studentL(张三,男);student*p;p=&L;psname();pssex();psage();}楼主的函数写的挺好的,而且调用也很好,还用到了指针,想和你交个朋友一块学习C++,希望楼主加我的百度空间号。谢谢!
strcpy(age,20);这个来的还有你程序运行最后的时候要运行析构函数~L_student(){ coutnameendlsexendlageendl;}就这个输出了age 更多有关「c++ 一个小程序不好用」的疑问请扫码关注微信公开课+小程序!了解更多