C++自学笔记
papyyaya
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
io流笔记(二)
文件简单写入读出操作#include<iostream>#include<string>#include<fstream>using namespace std;struct AA{ int age; string name;};int main(){ //向文件里写入文字 fstream file; file.open("test.txt", ios::out | ios::binary); if (!file) { cout <原创 2021-06-20 16:32:36 · 93 阅读 · 0 评论 -
io流之笔记
输出流#include<iostream>#include<iomanip>using namespace std;int main(){ cout << "cout" << endl; cerr << "cerr" << endl; clog << "clog" << endl; //输出一个字符 cout.put('0')<<endl; cout.put('i') <原创 2021-06-19 21:12:24 · 115 阅读 · 0 评论 -
链式栈和队列以及重载,const,void(*)补充
一:C++版链式栈#include<iostream>#include<string>using namespace std;//抽象类class stack{ //纯虚函数public: virtual~stack() { } virtual void push(int data) = 0; virtual void pop() = 0; virtual int& getTop() = 0; virtual int sizeStack(原创 2021-06-19 16:48:58 · 137 阅读 · 0 评论 -
多态与虚函数
多态:#include<iostream>#include<string>using namespace std;class father {public: father(string name,int money):name(name),money(money){} void print() { cout << name << ":" << money << endl; }protected: string原创 2021-06-13 12:03:30 · 188 阅读 · 0 评论 -
继承(单继承,多继承,虚继承,权限问题)
一:继承分类单继承多继承虚继承二:继承方式publicprotectedprivate三:继承语法父类 基类子类 派生类class 子类名:继承方式 父类名{}继承中权限问题:权限限定词,只会加强父类中成员在子类中的权限体现#include<iostream>using namespace std;class A{public: A(int Ap,int Bp,int Cp):Ap(Ap),Bp(Bp),Cp(Cp){} int Ap; vo原创 2021-06-11 17:04:07 · 218 阅读 · 1 评论 -
C++的重载(类重载,友元重载,流重载)
C++的重载一、运算符重载作用:赋予运算符具有操作自定义类型功能实质:调用函数的过程函数返回值 函数名(参数){函数体} 函数名:operator加上运算符重载运算符有两种形式:1.1 友元形式重载运算符(函数参数 = 操作数)ex:两个类成员相加,则需要重载+号class score{public: score(){} score(int math, int english) :math(math), english(english) {} int &getM原创 2021-06-10 17:08:59 · 390 阅读 · 0 评论 -
C++特殊成员const,static,友元
C++特殊成员一、const1.1 const 数据成员a、只能通过初始化参数列表的方式初始化b、一旦被初始化,不能被修改class A{public: A(int num,int age):num(num)//num必须用参数列表形式 { this->age = age; }protected: const int num;//num被const修饰 int age;};1.2 const 成员函数a、const位置是放在函数后面b、此函数可以和普通函数共存形成原创 2021-06-08 22:11:05 · 107 阅读 · 0 评论 -
类 和 对象
一、类和对象初始1、如何去产生一个类class A{ public://该权限下一般是接口函数 protected://该权限下一般写属性 private://若没有指明权限,则默认为private};1、如何去产生一个对象 类型+变量名int main(){ A mm;//产生一个对象 A arrayMM[3]; A *pMM = &mm; A *ppMM = new A; A *ppArrayMM = new A[3]; return 0;}2、如何原创 2021-06-07 21:07:35 · 101 阅读 · 0 评论
分享