01./*
02.* 程序的版权和版本声明部分
03.* Copyright (c)2012, 烟台大学计算机学院学生
04.* All rightsreserved.
05.* 文件名称: duixiang.cpp
06.* 作 者:晓晨
07.* 完成日期:2013年3月23日
08.* 版本号: v1.0
09.* 输入描述:无
10.* 问题描述:无
# include <iostream>
using namespace std;
class Student
{
public:
void set_data(int n,char*p,char s);
void display();
char sex;
private:
int num;
char name[20];
};
void Student::set_data(int n,char *p,char s)
{
num=n;
strcpy(name,p);
sex=s;
}
void Student::display()
{
cout<<"num: "<<endl;
cout<<"name: "<<endl;
cout<<"sex: "<<endl;
}
int main()
{
Student stud1;
stud1.set_data(1,"he",'f');
stud1.sex='m';
stud1.display();
return 0;
}
总结:
1,不能存取声明在student类中的私有成员sex,数据成员是字符型。