![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++
a我的
这个作者很懒,什么都没留下…
展开
-
Effective c++第五章(条款26-条款30)
第五章:实现实现条款26:尽可能延后变量定义式的出现时间(Postpone variable definitions as long as possible)声明一个变量其带有构造函数和析构函数,我们必须小心这点std::string encryptPassword(const std::string password){ using namespace std; string encrypted; if(password.length()< MinimumPasswordL原创 2021-05-31 00:32:58 · 361 阅读 · 3 评论 -
effective c++第四章(条款18-25)
第四章:设计与声明设计与声明条款18:让接口容易被正确使用,不易被使用(Make interfaces easy to use correctly and hard to use incorrectly)假设有如下代码class Date{public: Date(int month,int day,int year); ...};看似这个接口合理,但是客户很容易犯下错误Date(30,3,1995); //错误Date(2,30,1995); //错误都以错原创 2021-05-16 23:56:18 · 201 阅读 · 0 评论 -
Effective c++ 第三章(条款13-17)
第三章:资源管理资源管理条款13:以对象管理资源(Use objects to manage resources)class Investment{...}; //创建一个类Investment* creatInvestment(); //使用factory functionvoid f(){ Investment* pInv = creatInvestment(); //调用factory函数 ... delete pInv;原创 2021-05-14 15:21:10 · 217 阅读 · 2 评论 -
Effective c++ 第二章(条款05-12)
第二章:构造/析构/赋值运算条款05:了解c++默默编写并调用哪些函数(Know what functions c++ silently writes and calls)我们写一个空class后class Empty{}; //空类经过c++处理之后class Empty{public: Empty() {...} //default构造函数 Empty(const Empty& rhs) {...}原创 2021-05-13 16:00:59 · 136 阅读 · 0 评论 -
Effective c++第一章(条款01-04)
从5月11日开始看effective c++,半年没看c++了,现在看居然还能看懂QAQ(我属于小白类型,连入门都算不上),把一些自己看完之后的重点总结写一下,便于今后可以回过来看看自己有什么收获。话不多说,开始今天的第一篇!!第一章:让自己习惯c++让自己习惯c++条款01:视C语言为一个语言联邦(View C++ as a federation of languages)说实话这个主要就是让我们了解一下c++这门语言,讲的就是四点:1. C C++是以C为基础;2. Object-Oriente原创 2021-05-12 20:32:46 · 114 阅读 · 4 评论 -
大话设计模式迭代器模式c++实现
迭代器模式其他二十三种设计模式#include<iostream>#include<vector>#include<string>//迭代模式//--基本看的别人的using namespace std;typedef string object;//抽象迭代器类class Iterator {public: virtual object First() = 0; virtual object Next() = 0; virtual boo原创 2021-03-02 15:00:37 · 123 阅读 · 0 评论 -
大话设计模式解释器模式c++实现
解释器模式其他二十三种设计模式#include<iostream>#include<vector> #include<sstream> //提供stringstreamusing namespace std;//解释器模式//内容类class PlayContext {public: void SetPlayText(string _text) { this->text = _text; } string GetPlay原创 2021-03-02 14:58:09 · 136 阅读 · 0 评论 -
大话设计模式状态模式c++实现
状态模式其他二十三种设计模式#include<iostream>using namespace std;//状态模式class DoWork;//抽象状态类class State {public: virtual void WriteProgram(DoWork* _work) = 0;};//添加具体状态类class ForenoonState :public State {public: virtual void WriteProgram(DoWork* _原创 2021-03-02 14:54:48 · 95 阅读 · 0 评论 -
大话设计模式访问者模式c++实现
访问者模式其他二十三种设计模式#include<iostream>#include<list>using namespace std;//访问者模式class Action;//抽象对象类class Person {public: virtual void Accept(Action* _visitor) = 0;};class Man;class Woman;//抽象状态类class Action {public: virtual void原创 2021-03-02 14:52:41 · 91 阅读 · 0 评论 -
大话设计模式备忘录模式c++实现
备忘录模式其他二十三种设计模式#include<iostream>using namespace std;//备忘录模式//角色状态备忘录类class RoleStateMemento {public: RoleStateMemento(int _vit,int _atk,int _def) { this->vit = _vit; this->atk = _atk; this->def = _def; } void SetVitality(in原创 2021-03-02 14:50:34 · 108 阅读 · 0 评论 -
大话设计模式中介者模式模式c++实现
中介者模式其他二十三种设计模式#include<iostream>using namespace std;//中介者模式class Country;//联合国机构class UnitedNations {public: virtual void Declare(string _message, Country* _colleague) = 0;};//国家class Country {public: Country(UnitedNations* _mediato原创 2021-03-02 14:48:37 · 96 阅读 · 0 评论 -
大话设计模式责任链模式c++实现
责任链模式其他二十三种设计模式#include<iostream>using namespace std;//责任链模式//要求类class Request {public: void RequestType(string _requestType) { this->requestType = _requestType; } string GetRequestType() { return this->requestType; } void Requ原创 2021-03-02 14:45:48 · 76 阅读 · 0 评论 -
大话设计模式观察者模式c++实现
观察者模式其他二十三种设计模式#include<iostream>#include<list>using namespace std;//观察者模式//抽象观察者类class AbstractObserver {public: virtual void Update(string) = 0;};//抽象通知者类class AbstractSubject {public: //增加观察者 virtual void Attach(AbstractObse原创 2021-02-27 10:22:06 · 113 阅读 · 1 评论 -
大话设计模式命令模式c++实现
命令模式其他二十三种设计模式#include<iostream>#include<queue>using namespace std;//命令模式//Receiver类class Barbecuer {public: void BakeMutton() { cout << "烤羊肉串!" << endl; } void BakeChickWing() { cout << "烤鸡翅!" << endl;原创 2021-02-27 10:20:01 · 99 阅读 · 0 评论 -
大话设计模式策略模式c++实现
策略模式其他二十三种设计模式#include<iostream>using namespace std;//策略模式(Strategy):定义算法家族,分别封装起来,让算法之间可以相互替换,且不会影响到使用算法的Client客户//抽象收费策略class CashSuper {public: virtual double acceptCash(double money) = 0;};//正常收费类class CashNormal :public CashSuper {原创 2021-02-27 10:16:28 · 256 阅读 · 0 评论 -
大话设计模式模板方法模式c++实现
模板方法模式其他二十三种设计模式#include<iostream>using namespace std;//模板方法模式//模板类class TestPaper{public: void TestQuestion1() { cout << "问题1: **" << endl; cout << "答案: " << Answer1() << endl; } void TestQuestion2() {原创 2021-02-27 10:12:50 · 129 阅读 · 0 评论 -
大话设计模式外观模式c++实现
外观模式其他二十三种设计模式#include<iostream>using namespace std;//外观模式(Facade):为子系统中的一组接口提供一个一致的界面,此模式定义一个高层接口,使得子系统更加容易使用//子系统类class Stock1 {public: void Sell() { cout << "股票1卖出" << endl; } void Buy() { cout << "股票1买入" <<原创 2021-02-27 10:10:53 · 89 阅读 · 1 评论 -
大话设计模式代理模式c++实现
代理模式其他二十三种设计模式#include<iostream>using namespace std;//代理模式//被追求者类class Girl {public: void Name(string _name) { this->name = _name; } string GetName() { //void类型时会导致没有与"<<"匹配的运算符 return name; //不能直接cout<<name,需要re原创 2021-02-27 10:08:41 · 103 阅读 · 0 评论 -
大话设计模式享元模式c++实现
享元模式其他二十三种设计模式#include<iostream>#include<map>using namespace std;//享元模式class User {public: User(string _name) { this->name = _name; } string GetName() { return name; }private: string name;};class WebSite{public: vir原创 2021-02-27 10:06:39 · 102 阅读 · 0 评论 -
大话设计模式享元模式c++实现
享元模式其他二十三种设计模式#include<iostream>#include<map>using namespace std;//享元模式class User {public: User(string _name) { this->name = _name; } string GetName() { return name; }private: string name;};class WebSite{public: vir原创 2021-02-27 10:04:09 · 58 阅读 · 0 评论 -
大话设计模式组合模式c++实现
组合模式其他二十三种设计模式#include<iostream>#include<list>using namespace std;//组合模式class Company {public: Company(string _name) { this->name = _name; } virtual void Add(Company *c) = 0; virtual void Remove(Company* c) = 0; virtual void原创 2021-02-27 10:01:15 · 103 阅读 · 0 评论 -
大话设计模式桥接模式c++实现
桥接模式其他二十三种设计模式#include<iostream>using namespace std;//桥接模式:将抽象部分与实现部分分离,使它们可以独立变化//实现部分类class Implementor {public: virtual void Operation() = 0;};//具体实现类class ConcreteImplementorA :public Implementor {public: virtual void Operation()原创 2021-02-27 09:54:08 · 113 阅读 · 0 评论 -
大话设计模式装饰模式c++实现
装饰模式其他二十三种设计模式#include<iostream>using namespace std;//装饰模式//人类class Person {public: Person(){} //删除会无法引用子类(TShirts、BigTrouser...)的默认构造函数 Person(string _name) { this->name = _name; } virtual void Show() { cout <<原创 2021-02-26 17:51:26 · 119 阅读 · 0 评论 -
大话设计模式适配器模式c++实现
适配器模式其他二十三种设计模式#include<iostream>using namespace std;//适配器模式//Targetclass Player {public: Player(string _name) { this->name = _name; } virtual void Attack() = 0; virtual void Defense() = 0;protected: string name;};class Forward原创 2021-02-26 17:47:12 · 128 阅读 · 0 评论 -
大话设计模式建造者模式c++实现
建造者模式其他二十三种设计模式#include<iostream>#include<list>using namespace std;//建造者模式//产品类class Product {public: void Add(string _parts) { parts->push_back(_parts); } void Show() { cout << "产品创建: "; for (list<string>::iter原创 2021-02-26 17:44:06 · 107 阅读 · 0 评论 -
大话设计模式原型模式c++实现
原型模式其他二十三种设计模式#include<iostream>using namespace std;//原型模式(Prototype)class Person {public: virtual Person* Clone() = 0;};class WorkExperience :public Person{public: WorkExperience() {} ~WorkExperience() {} WorkExperience(string _workD原创 2021-02-26 17:41:57 · 125 阅读 · 0 评论 -
大话设计模式单例模式c++实现
单例模式其他二十三种设计模式#include<iostream> using namespace std;//单例模式--懒汉式class Singleton_lazy {private: Singleton_lazy() { cout << "懒汉" << endl; } static Singleton_lazy* pSingleton; //静态成员变量的初始化有些特别,是在类外初始化且不能在带有 static 关键字;public: s原创 2021-02-26 17:39:06 · 167 阅读 · 0 评论 -
大话设计模式抽象工厂模式c++实现
抽象工厂模式其他二十三种设计模式#include<iostream>using namespace std;//抽象工厂模式//抽象用户类class AbstractUser {public: virtual void Inser() = 0;};//具体用户类class SqlserverUser :public AbstractUser {public: virtual void Inser() { cout << "在SQL server中给U原创 2021-02-26 17:35:56 · 206 阅读 · 0 评论 -
大话设计模式工厂方法模式c++实现
工厂方法模式其他二十三种设计模式#include<iostream>using namespace std;//工厂方法模式//抽象运算类class AbstractOperation {public: virtual int GetResult() = 0; void Get(int _NumberA, int _NumberB) { this->NumberA = _NumberA; this->NumberB = _NumberB; }prote原创 2021-02-26 17:27:25 · 191 阅读 · 0 评论 -
大话设计模式二十四种模式全部c++实现
二十四种设计模式全部c++实现简单工厂模式.原创 2021-02-26 17:20:31 · 1000 阅读 · 1 评论 -
大话设计模式简单工厂模式c++实现
简单工厂模式大部分都是大话设计模式上的案例,工厂方法对着简单工厂写的,和书上案例不一致#include<iostream>using namespace std;//简单工厂模式//抽象类class AbstractOperation {public: virtual int GetResult() = 0; void Get(int _NumberA,int _NumberB){ this->NumberA = _NumberA; this->Numbe原创 2021-02-26 17:15:18 · 494 阅读 · 0 评论 -
十七章第一题
#include<iostream>int main(){ using std::cout; using std::endl; using std::cin; char ch; while (cin.get(ch)) { if (ch != '$') cout << ch; else { cin.putback(ch); break; } } if (!cin.eof()) { cin.get(ch); cout <原创 2020-09-30 13:21:14 · 72 阅读 · 0 评论 -
十六章第九题
#include<iostream>using namespace std;#include<vector>#include<list>#include<ctime>#include<string>#include<algorithm>const int NUM = 10000;int main(){ srand(time(0)); vector<int> vi0(NUM); for (int i =原创 2020-09-28 11:16:01 · 66 阅读 · 0 评论 -
第十六章第八题
#include<iostream>using namespace std;#include<vector>#include<string>#include<algorithm>int main(){ vector<string> Mat, Pat, Total; string name; cout << "the Mat book title: "; while (getline(cin, name)) {原创 2020-09-28 10:18:08 · 105 阅读 · 0 评论 -
十六章第七题
#include<iostream>using namespace std;#include<vector>#include<algorithm>const int num = 51;vector<int> lotto(const int num, int n = 0);原创 2020-09-28 09:15:36 · 270 阅读 · 0 评论 -
十六章第五题
#include<iostream>#include<list>#include<algorithm>#include<vector>using namespace std;template<class T>int reduce(T ar[], int n);int main(){ const int num = 10; long arr[num] = { 1,5,5,8,3,3,3,2,9,6 }; string str[n原创 2020-09-27 21:43:28 · 76 阅读 · 0 评论 -
十六章第四题
#include<iostream>#include<list>#include<algorithm>#include<vector>using namespace std;int reduce(long ar[], int n);int main(){ const int num = 10; long arr[num] = { 1,5,5,8,3,3,3,2,9,9 }; int n = reduce(arr, num); cout &原创 2020-09-27 21:34:58 · 76 阅读 · 0 评论 -
十六章第三题
自己定义一个txt文件 const string filename = "diyi.txt"; std::vector<string> wordlist; ifstream fin; fin.open(filename.c_str()); if (!fin.is_open()) { cout << "can't open\n"; exit(EXIT_FAILURE); } string temp; while (fin >> temp) wo原创 2020-09-27 21:22:05 · 85 阅读 · 0 评论 -
十六章第二题
基本看的别人的,不会啊!cctype字符函数库#include<iostream>#include<string>#include<cctype>using std::string;using std::cout;using std::cin;bool fu(const string& str);int main(){ string name; getline(cin, name); while (cin&&name.si原创 2020-09-27 20:36:52 · 52 阅读 · 0 评论 -
c++第十四章第四题
#ifndef PERSON_H_#define PERSON_H_#include <string>class Person{public: Person() { lastname = '\0', firstname = '\0'; } ~Person() {}; Person(const std::string& fun, const std::string& fin) :lastname(fun),firstname(fin){} virtual vo原创 2020-09-23 23:03:18 · 65 阅读 · 0 评论