3-1调试类
[cpp]
#include <iostream>
using namespace std;
{
private:
int num;
char name[20];
char 易做图;
public:
void set_data(int n, char *p,char s)
{
num=n;
strcpy(name,p);
易做图=s;
}
void display( )
{
cout<<"num: "<<num<<endl;
cout<<"name: " <<name<<endl;
cout<<"易做图: " <<易做图<<endl;
}
};
int main()
{ Student stud1,stud2; //(1)
stud1.set_data(1,"He",'f'); //(2)
stud2.set_data(2,"She",'m'); //(3)
stud1.display(); //(4)
stud2.display(); //(5)
return 0;
}
运行结果:
违反封装原则,直接给私有成员赋值、访问私有对象等:
在实现对类成员函数时不指定作用域:
调用stud1.set_data()函数时,实参出现不当类型:
补充:软件开发 , C++ ,