c++学习
小句
这个作者很懒,什么都没留下…
展开
-
c++学习-oop-顺序队列
//[Error] ‘copy’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point ofcopy函数显示没有声明,头文件也弄了几个,就是不行。。。#ifndef _Q1_H#define _Q1_H#include<algorithm>#include<vector>//[Error] 'copy' was no原创 2021-03-16 17:36:48 · 259 阅读 · 0 评论 -
c++学习-oop-模板与泛型编程
#include<iostream>#include<iomanip>using namespace std;class Queue{ struct Node { int a; Node *next; };public: Queue(); void push(int b); void pop(); int getLength(); virtual void print();private: Node *head;//头节点存的是队列的长度,原创 2021-03-15 16:12:21 · 95 阅读 · 0 评论 -
c++学习-oop-纯虚函数与抽象类
/* Date: 14/03/21 20:33 Description: 纯虚函数与抽象类 纯虚函数 抽象类-抽象数据类型 任何包含一个或多个纯虚函数的类都是抽象类 不要创建这个类的对象,应该继承它 务必覆盖从这个类继承的纯虚函数 实现纯虚函数 c++接口 就是只包含纯虚函数的抽象基类 */#include<iostream>using namespace std;class Shape{public: Shape(){} virtual ~Sha原创 2021-03-15 14:33:46 · 111 阅读 · 0 评论 -
c++学习-oop-静态成员与继承
/* Date: 14/03/21 20:08 Description: 静态成员与继承 基类中的static成员,在整个继承层次中只有一个示例 在派生类中访问static成员的方法 1.基类名::成员名 2.子类名::成员名 3.对象.成员名 4.指针->成员名 5.成员名 */#include<iostream>using namespace std;class A{public: static size_t object_count()原创 2021-03-14 20:32:33 · 93 阅读 · 0 评论 -
c++学习-oop-友元与继承
/* Date: 14/03/21 19:30 我----------》 我爸爸 《-----友元-----》 我爸爸 《---------你 Description: 友元与继承 友元可以访问类的private和protected成员 友元关系不能继承,要明确授予友元 */#include<iostream>using namespace std;class Base//你爸爸 { friend class Frnd;protected: int i原创 2021-03-14 20:08:24 · 103 阅读 · 0 评论 -
c++学习-oop-转换与继承
/* Date: 14/03/21 18:08 Description: 转换与继承 派生类->基类 引用转换 对象转换 基类->派生类 基类到派生类的自动转换不存在 强制转换 */#include<iostream>using namespace std;class Item_base{public: Item_base(const string& book = "",double sales_price = 0.0) :is原创 2021-03-14 19:26:30 · 71 阅读 · 0 评论 -
c++学习-oop-派生类的构造函数和析构函数
/* Date: 14/03/21 15:01 Description: 派生类的构造函数和析构函数 派生类的构造函数(执行顺序) 执行基类的构造函数 执行成员对象的构造函数 执行派生类的构造函数*/#include<iostream>using namespace std;class Dad{public: int x;};class Son:public Dad{public: int y; };class Base1{publi原创 2021-03-14 17:50:15 · 107 阅读 · 0 评论 -
c++学习-oop-三种继承
/* Date: 14/03/21 14:01 Description: 三种继承 共有,私有,受保护继承 class B :public A class B :private A class B :private A 接口继承 public和实现继承 private private 修改继承访问(去除个别成员) 默认继承访问级别 */#include<iostream>using namespace std;class A{public: A()原创 2021-03-14 14:53:40 · 81 阅读 · 0 评论 -
c++学习-oop-动态绑定
/* Date: 14/03/21 12:46 Description: 动态绑定 这节课老师讲的特别好 多态性 从派生类到基类的转换 引用或指针既可以指向基类对象,也可以指向派生类对象 只有通过引用或指针调用虚函数才会发生动态绑定 Item_base <--- Bulk_item */#include<iostream>using namespace std;class Item_base{public: Item_base(const str原创 2021-03-14 13:57:55 · 86 阅读 · 0 评论 -
c++学习-oop-定义基类和派生类
/* Date: 13/03/21 20:26 Description: 定义基类和派生类 父类 Item_base <----- 子类 Bulk_item 基类: virtual函数 protected成员 派生类 类派生列表 重定义vietual函数 可以访问基类的public和protected成员 */#include<iostream>using namespace std;class原创 2021-03-13 21:45:04 · 83 阅读 · 0 评论 -
c++学习-oop-转换操作符
/* Date: 13/03/21 19:32 Description: 转换操作符 转换函数 operator int() const; 注意: 1.必须是成员函数 2.不能指定返回类型 3.形参表必须是空的 4.必须显示地返回一个指定类型的值 5.不应该改变被转换对象,通常定义为const */#include<iostream>using namespace std;class Dog{public: Dog(string n,int a,d原创 2021-03-13 20:25:25 · 54 阅读 · 0 评论 -
c++学习-oop-函数对象
/* Date: 12/03/21 20:50 Description: 函数对象 重载函数调用操作符 函数对象:定义了调用操作符的类,其对象称为“函数对象” 一元函数对象 一元谓词 二元函数对象 二元谓词 */#include<iostream>#include<vector> #include<list>#include<algorithm>using namespace std;class absInt{publ原创 2021-03-13 19:23:54 · 87 阅读 · 1 评论 -
c++学习-oop-重载自增自减操作符
/* Date: 12/03/21 19:55 Description: 重载自增自减操作符 自增、自减操作符 ++ -- 重载前缀形式、后缀形式的自增自减操作符 operator++(); operator++(int); */#include<iostream>#include<cstring>using namespace std;class String{public: String(char const *chars = "");原创 2021-03-12 20:48:11 · 99 阅读 · 0 评论 -
c++学习-oop-重载成员访问操作符
main.cpp/* Date: 12/03/21 16:01 Description: 重载成员访问操作符 成员访问操作符 解引用操作符:* 用于指针 箭头操作符:-> 用于对象 复习 管理指针成员 定义智能指针类 class Pointer ----> class String */#include<iostream>#include "string.h"#include "pointer.h"using namespace std原创 2021-03-12 19:52:44 · 89 阅读 · 1 评论 -
c++学习-oop-重载下标操作符
/*: Date: 12/03/21 15:25 Description: 重载下标操作符 下标操作符 [] 两个版本 可变成员函数 常量成员函数 */#include<iostream>#include<cstring>using namespace std;class String{public: String(char const *chars = ""); char &operator[](size_t index) thr原创 2021-03-12 15:59:01 · 72 阅读 · 0 评论 -
c++学习-oop-重载赋值操作符
/* Date: 12/03/21 14:20 Description: 重载赋值操作符 赋值操作符 == += -= *= /= %= &= |= ^= <<= >>= 赋值操作符必须返回对*this的引用 */#include<iostream>#include<cstring>using namespace std;class String{public: String(char const *char原创 2021-03-12 15:22:52 · 79 阅读 · 0 评论 -
c++学习-oop-重载关系操作符2
#include<iostream>using namespace std;class Date{public: Date(int m=0,int d=0,int y=0):month(m),day(d),year(y){} bool operator==(Date &dt)const; bool operator!=(Date &dt)const; bool operator<(Date &dt)const; bool operato原创 2021-03-12 14:19:13 · 63 阅读 · 0 评论 -
c++学习-oop-重载关系操作符1
/* Date: 11/03/21 20:29 Description: 重载关系操作符 关系操作符 == != < <= > >= */#include<iostream>using namespace std;class Sales_item{public: Sales_item():units_sold(0),revenue(0.0){} Sales_item(const string& book,const unsig原创 2021-03-12 13:11:04 · 81 阅读 · 0 评论 -
c++学习-oop-重载算数运算符
/* Date: 11/03/21 19:36 Description:重载算数运算符 算术运算符 + += - -= * *= / /= % %/ 为了与内置操作符保持一致,算术操作符通常产生一个新值 一般应使用复合赋值实现算术操作符 例如:用+=来实现+ */#include<iostream>using namespace std;class Sales_item{public: Sales_item():units_sold(0),rev原创 2021-03-11 20:27:21 · 185 阅读 · 0 评论 -
c++学习-oop-重载输入输出操作符
/* Date: 11/03/21 18:55 Description: 重载输入输出操作符 输出操作符<<重载 非成员函数->友元函数 少做格式化 输入操作符重载>>重载 处理输入操作的错误 */#include<iostream>using namespace std;class Sales_item{public: Sales_item():units_sold(0),revenue(0.0){} Sales_item原创 2021-03-11 19:36:03 · 91 阅读 · 0 评论 -
c++学习-oop-重载操作符的定义
/* Date: 11/03/21 15:22 Description: 重载操作符的定义 可以重载的操作符(42个) + - * / % ^ & | ~ ...... 不可以重载的操作符(4个) :: .* . ?: 重载操作符的注意事项 */#include<iostream>using namespace std;class Person{ //重载加法运算符 public: void operator+(const Person&am原创 2021-03-11 16:17:27 · 54 阅读 · 0 评论 -
c++学习-oop-管理指针成员
plain-ptr.hclass AHasPtr{public: AHasPtr(int *p,int i):ptr(p),val(i){} int *get_ptr()const {return ptr;} int get_int()const{return val;} void set_ptr(int *p){ptr = p;} void set_int(int i){val = i;} int get_ptr_val()const{return *ptr;} void.原创 2021-03-11 15:20:17 · 88 阅读 · 0 评论 -
c++学习-oop-深复制、浅复制
/* Date: 10/03/21 20:45 Description: 深复制、浅复制 复制构造函数/拷贝构造函数 浅复制/浅拷贝/位拷贝 深复制/深拷贝 */#include<iostream>#include<cstring>using namespace std;class CDemo{public: CDemo(int pa,char *cstr) { this->a = pa; this->str = new char[.原创 2021-03-10 21:26:44 · 90 阅读 · 0 评论 -
c++学习-oop-析构函数
/* Date: 10/03/21 20:12 Description: 析构函数 构造函数:获取资源 析构函数:释放资源 合成的析构函数 三法则(rules of three) :写析构函数必须同时也要写复制构造函数和赋值运算符 */#include<iostream>using namespace std;class Sales_item{public: private: string isbn; int units_sold; double reven原创 2021-03-10 20:41:44 · 78 阅读 · 0 评论 -
c++学习-oop-复制构造函数和赋值操作符
/* Date: 09/03/21 21:00 Description: 复制构造函数和赋值操作符 复制构造函数的适用情况 1.对象的定义形式-复制初始化 2.形参与返回值 3.初始化容器元素 4.构造函数与数组元素 赋值操作符 1.重载赋值操作符 2.复制和赋值常一起使用 合成的复制构造函数和赋值操作符 定义自己的复制构造函数和赋值操作符 */#include<iostream>#include<vector>using namespa原创 2021-03-10 20:11:04 · 72 阅读 · 0 评论 -
c++学习-oop-static类成员
/* Date: 09/03/21 19:44 Description: static 类成员 使用类的static成员的优点 定义static成员 使用类的static成员 static成员函数 static数据成员 */#include<iostream>using namespace std;class Account{public: Account(string name,double money):owner(name),amount(money){}原创 2021-03-09 20:59:24 · 50 阅读 · 0 评论 -
c++学习-oop-友元-友元函数、友元类
/* Date: 09/03/21 16:21 Description: 友元-友元函数、友元类 友元关系 三种友元 1.普通函数(非成员函数) 2.类 3.类的成员函数 */#include<iostream>using namespace std;class Screen;class Dog{public: int foo(Screen& screen); int koo(Screen& screen);}; class原创 2021-03-09 19:42:47 · 104 阅读 · 0 评论 -
c++学习-oop-构造函数
/* Date: 09/03/21 11:34 Description: 构造函数 作用:保证每个对象的数据成员具有合适的初始值 构造函数初始化式(初始化列表) 默认实参与构造函数 默认构造函数 隐式类类型转换 类成员的显示初始化 */#include<iostream>#include<istream> using namespace std;class Person{private: string name; int age;public:原创 2021-03-09 16:19:43 · 95 阅读 · 0 评论 -
c++学习-oop-类作用域
/* Date: 09/03/21 10:45 Description: 类作用域 类作用域 1.使用类的成员 2.作用域与成员定义 3.形参表和函数体处于类作用域中 4.函数返回类型不一定在类作用域中 类作用域中的名字查找 1.类成员声明的名字查找 2.类成员定义中的名字查找 3.类成员遵循常规的块作用域名字查找 4.函数作用域之后,在类作用域中查找 5.类作用域之后,在外围作用域中查找 */#include<iostream>using n原创 2021-03-09 11:34:05 · 55 阅读 · 0 评论 -
c++学习-oop-隐含的this指针
/* Date: 08/03/21 19:30 Description: 隐含的this指针 何时使用this指针 返回*this 从const成员函数返回*this 基于const的重载 可变数据成员 */#include<iostream>using namespace std;class Person{public: Person(const string& nm,const string &addr):name(nm),address(ad原创 2021-03-08 21:00:07 · 126 阅读 · 0 评论 -
c++学习-oop-类定义3
/* Date: 08/03/21 18:03 Description: 类定义3 类声明->前向声明 类定义 类对象 演变:c -> c++ */#include<iostream>using namespace std;class Y;class X{private: Y *ptr;};class Y{private: X *ptr; X obj;};class Screen;//类声明 class LinkScreen原创 2021-03-08 19:27:59 · 52 阅读 · 0 评论 -
c++学习-oop-类定义2
/* Date: 08/03/21 15:48 Description: 类定义2 同一类型的多个数据成员 使用类型别名来简化类 成员函数可被重载 -定义重载成员函数 显法指定inline成员函数 */#include<iostream>using namespace std;class Screen{public: typedef string::size_type index; // Screen(){} Screen(index ht = 0,ind原创 2021-03-08 18:01:45 · 48 阅读 · 0 评论 -
c++学习-oop-类定义1
/* Date: 08/03/21 13:38 Description: 类定义1 类成员 构造函数 成员函数 访问标号实施抽象和封装 public private protected */#include<iostream>using namespace std;// 销售 项目class Sales_item{public: Sales_item(string book,unsigned units,double amout):isbn(b原创 2021-03-08 15:48:05 · 55 阅读 · 0 评论 -
c++学习-基础- 字符串流
/* Date: 07/03/21 16:47 Description: 字符串流 字符串流:内存中的输入输出 istringstream,ostringstream,stringstream 字符串流stringstream特定的操作 stringstream strm; stringstream strm(s); strm.str() strm.str(s) stringstream提供的转换和格式化 */#include<iostream>#includ原创 2021-03-07 17:43:36 · 109 阅读 · 0 评论 -
c++学习-基础-一个打开并检查输入文件的程序
#ifndef _GET_H#define _GET_H#include<iostream>std::istream& get(std::istream& in);#endif#include "get.h"#include <stdexcept>std::istream& get(std::istream& in){ int ival; while(in>>ival , !in.eof()) { if(原创 2021-03-07 16:43:42 · 89 阅读 · 0 评论 -
c++学习-基础-文件模式
/* Date: 07/03/21 14:40 Description: 文件模式 文件模式选项 in,out,app,ate,trunc,binary 文件模式组合 out out | app out | trunc in in | out in | out | ate in | out | trunc */#include<iostream>#include<fstream>using namespace std;int main(){原创 2021-03-07 15:47:13 · 245 阅读 · 0 评论 -
c++学习-基础-标准库重点习题解答2
#include<iostream>#include<fstream>#include<vector>using namespace std;int fileToVector(string fileName,vector<string>& svec){ ifstream inFile(fileName.c_str()); if(!inFile) return 1; string s; // while(getline(原创 2021-03-07 11:45:33 · 80 阅读 · 0 评论 -
c++学习-基础-标准库重点习题解答1
#ifndef _GET_H#define _GET_H#include<iostream>std::istream& get(std::istream& in);#endif#include "get.h"#include <stdexcept>std::istream& get(std::istream& in){ int ival; while(in>>ival , !in.eof()) { if(i原创 2021-03-06 16:56:22 · 60 阅读 · 0 评论 -
c++学习-基础-文件流对象的使用
/* Date: 06/03/21 12:46 Description: 文件流对象的使用 将文件流对象绑定到文件上 检查文件是否打开成功 将文件流与新文件重新绑定 清除文件流的状态 */#include<iostream>#include<fstream>using namespace std;int main(){ // ofstream outfile("test.txt");// outfile<<"hello file!";/原创 2021-03-06 15:36:27 · 185 阅读 · 0 评论 -
c++学习-基础-条件状态
/* Date: 06/03/21 11:37 Description:条件状态 strm::iostate s.eof() strm::badbit s.fail() strm::failbit s.bad() strm::eofbit s.good() s.clear() s.clear(flag) s.setstate(flag) s.rdstate()*/#include<原创 2021-03-06 12:39:40 · 132 阅读 · 0 评论