C++类和对象(lesson 1:this指针)
1)结构体和类
C语言中,结构体中只能定义变量,在C++中,结构体内不仅可以定义变量,也可以定义函数
C语言中结构体
struct Student
{
void StudentIn(const char* name, const char* gender, int age)
{
strcpy(_name, name);
strcpy(_gender, gender);
_age = age;
}
void PrintStudentIn()
{
cout << _name << " " << _gender << " " << _age << endl;
}
char _name[20];
char _gender[3];
int _age;
};
int main()
{
Student s;
s.StudentIn("Peter", "男"