1. 面向对象
1.1 结构体与类
struct Student {
}
class Student {
}
1.2 类的定义
#include<iostream>
using namespace std;
class Student {
public:
void setAge(int value){
age = value;
}
int getAage(){
return age;
}
private:
int age;
protected:
int name;
};
int main(){
Student stu;
stu.setAge(10);
cout<<"age = "<< stu.getAage() << endl;
return 0;
}
1.3 类的外部函数方法
#include<iostream>
#include<string>
using namespace std;
class Student {
public:
void setName(string value);
string getName();
private:
string name;
};
void Student::setName(string value) {
name = value;
}
string Student::getName(){
return name;
}
int main(){
Student stu;
stu.setName("li ming");
cout<<"getName = "<< stu.getName() << endl;
return 0;
}