C++ 入门速通-第5章【黑马】
内容来源于:黑马
集成开发环境:CLion
先前学习完了C++第1章的内容:
C++ 入门速通-第1章【黑马】-CSDN博客
C++ 入门速通-第2章【黑马】-CSDN博客
C++ 入门速通-第3章【黑马】-CSDN博客
C++ 入门速通-第4章【黑马】-CSDN博客
下面继续学习第5章:
面向对象入门:
简单案例:
// class 面向对象
#include <iostream>
using namespace std;
class Person
{
public:
// 封装属性
string name;
int age;
int height;
// 封装行为
void eat()
{
cout << "eat" << endl;
}
void sleep()
{
cout << "sleep" << endl;
}
void walk()
{
cout << "walk" << endl;
}
};
int main()
{
Person p1;
p1.name = "zhangsan";
p1.age = 18;
p1.height = 180;
cout << "name:" << p1.name << endl;
cout << "age:" << p1.age << endl;
cout << "height:" << p1.height << endl;
p1.eat();
p1.sleep();
p1.walk();
return 0;
}
class的基本语法:
类的访问修饰符:
未完待续。。。
C++一套通关系列课程在线笔记:https://www.yuque.com/bigdata-caoyu/newcp
参考:
第五章-01-面向对象入门_哔哩哔哩_bilibili