赞
踩
首先,明白c++和C语言的区别:
类的实现:
- struct Student
- {
- void SetStudentInfo(const string name, const string gender, int age)
- {
- strcpy(name, name);
- strcpy(gender, gender);
- age = age;
- }
- void PrintStudentInfo()
- {
- cout<<name<<" "<<gender<<" "<<age<<endl;
- }
- string name;
- string gender;
- int age;
- };
- class Student
- {
- void SetStudent(const char* name, const char* gender, int age)
- {
- strcpy(_name, name);
- strcpy(_gender, gender);
- _age = age;
- }
- void PrintStudent()
- {
- cout<<_name<<" "<<_gender<<" "<<_age<<endl;
- }
- char _name[20];
- char _gender[3];
- int _age;
- };
类的访问限定符:
类的实例化:用类类型创建对象的过程,称为类的实例化
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。