C++
Cpp
ccqq0507
这个作者很懒,什么都没留下…
展开
-
C++反射实现
基础版:只实现了通过对象的类名,获取到成员属性的name和type#include <string>#include<iostream>#include<map>#include<vector>#include<set>using namespace std;#define REFLECT_ATTR(type,name) ReflectManager __##name = ReflectManager(this,#type,.原创 2022-03-02 11:47:15 · 383 阅读 · 0 评论 -
智能指针的选择
// fowl.cpp -- auto_ptr a poor choice#include <iostream>#include <string>#include <memory>int main(){ using namespace std; auto_ptr<string> films[5] = { auto_ptr<string> (new string("Fowl Balls")),原创 2021-06-10 17:58:10 · 63 阅读 · 0 评论 -
使用atomics的使用
#include <iostream>#include <ctime>#include <mutex>#include <vector>#include <thread>#include <atomic>std::mutex mtx;size_t count = 0;//使用atomicstd::atomic<size_t> count_1(0);void threadFun(){ for (int原创 2021-06-01 10:50:37 · 89 阅读 · 0 评论 -
简单述三消游戏逻辑:
讲述三消游戏逻辑:项目简介:支持六种元素,以及障碍元素,行,列,彩虹特殊道具核心就是填充算法和一个匹配算法:填充:本文采用分步填充(即一次只向下移动一个单位)public bool Fill() { bool filledNotFinished = false;//判断本次填充是否完成 //Debug.Log("This is Fill1");//左上为(0,.0) for (int y = yRow - 2; y >=0; y--)/原创 2021-02-20 17:37:51 · 1573 阅读 · 0 评论 -
effective cpp 4
#include <iostream>#include <assert.h>using namespace std;class Rectangle{public: Rectangle(int h,int w) :height(h), widget(w) {} ~Rectangle() {} virtual void setHeight(int newHeight) { height = newHeight; } virtual void setWidth(int原创 2021-02-02 14:21:34 · 60 阅读 · 0 评论 -
Socket
socke1.简述大学学习网络基础的时候老师讲过,网络由下往上分为物理层、数据链路层、网络层、传输层、会话层、表示层和应用层。通过初步的了解,我知道IP协议对应于网络层,TCP协议对应于传输层,而HTTP协议对应于应用层,三者从本质上来说没有可比性,socket则是对TCP/IP协议的封装和应用(程序员层面上)。也可以说,TPC/IP协议是传输层协议,主要解决数据如何在网络中传输,而HTTP是应用层协议,主要解决如何包装数据。关于TCP/IP和HTTP协议的关系,网络有一段比较容易理原创 2021-01-29 16:43:58 · 1104 阅读 · 0 评论 -
CPPeffective3
#include <iostream>#include <assert.h>using namespace std;class Rectangle{public: Rectangle(int h,int w) :height(h), widget(w) {} ~Rectangle() {} virtual void setHeight(int newHeight) { height = newHeight; } virtual void setWidth(int原创 2021-01-27 20:37:05 · 72 阅读 · 0 评论 -
c++ effective3
#include <string>#include <iostream>#include <vector>//using std::string; //using namespace std:using namespace std;class Person{public: Person(); virtual ~Person();private: string name; string address;};Person::Person().原创 2021-01-20 15:00:43 · 57 阅读 · 0 评论 -
c++effective 2
#include<string>class Bitmap {};class Widget { Widget& operator=(const Widget& rhs);private: Bitmap* pb;};Widget& Widget::operator=(const Widget& rhs){ //if (this == &rhs) return *this; //delete pb; //pb = new Bitmap(*原创 2021-01-11 14:08:49 · 206 阅读 · 1 评论 -
effective cpp 1-10
#include <string>#include<stdlib.h>using namespace std;class name {public: static const int kk = 16; int arrar[kk]; enum {num= 5}; int arrs[num];};class TextBlock{public: TextBlock(std::string id) :text(id),pText(nullptr),textLengt原创 2021-01-06 20:06:23 · 69 阅读 · 0 评论 -
c++类型转换
// tv.h -- Tv and Remote classes#ifndef TV_H_#define TV_H_class Tv{public: friend class Remote; // Remote can access Tv private parts enum { Off, On }; enum { MinVal, MaxVal = 20 }; enum { Antenna, Cable }; enum { TV, DVD };原创 2020-12-23 21:10:07 · 51 阅读 · 0 评论 -
chapter14
// studentc.h -- defining a Student class using containment#ifndef STUDENTC_H_#define STUDENTC_H_using std::istream;using std::ostream;using std::cin;using std::string;#include <string> #include <valarray>class Student{private:原创 2020-12-23 16:28:43 · 138 阅读 · 0 评论 -
chapter13 jicheng
#ifndef TABTENN0_H_#define TABTENN0_H_#include <string>using std::string;// simple base classclass TableTennisPlayer{private: string firstname; string lastname; bool hasTable;public: TableTennisPlayer(const string& fn = "n原创 2020-12-21 20:12:29 · 124 阅读 · 0 评论 -
chapter12 classs and new
// bank.cpp -- using the Queue interface// compile with queue.cpp#include <iostream>#include <cstdlib> // for rand() and srand()#include <ctime> // for time()#include <cstring> #include <string>using std::cout;using原创 2020-12-18 19:09:40 · 96 阅读 · 0 评论 -
chapter11 use class
// mytime0.cpp -- implementing Time methods#include <iostream>#ifndef MYTIME0_H_#define MYTIME0_H_class Time{private: int hours; int minutes;public: Time(); Time(int h, int m = 0); void AddMin(int m); void AddHr(int h原创 2020-12-17 21:12:48 · 258 阅读 · 0 评论 -
chapter10 class
#ifndef STOCK00_H_#define STOCK00_H_#include <iostream>#include <string> class Stock // class declaration{private: enum { month = 12 };//const month = 12 error double costs[month];//static const int month = 12; ri std::stri原创 2020-12-16 17:07:23 · 102 阅读 · 0 评论 -
chapter9 namespace
#include <iostream>#ifndef COORDIN_H_#define COORDIN_H_struct polar{ double distance; // distance from origin double angle; // direction from origin};struct rect{ double x; // horizontal distance from origin .原创 2020-12-15 20:44:11 · 42 阅读 · 0 评论 -
chapter8 function exp
// inline.cpp -- using an inline function#include <iostream>#include <fstream>#include <cstdlib>using namespace std;void file_it(ostream& os, double fo, const double fe[], int n);const int LIMIT = 5;// an inline function defi原创 2020-12-09 20:35:17 · 84 阅读 · 0 评论 -
chapter7 function
// calling.cpp -- defining, prototyping, and calling a function#include <iostream>#include <array>#include <string>void simple(); // function prototypelong double probability(unsigned numbers, unsigned picks);const int Seasons =原创 2020-12-08 15:58:55 · 99 阅读 · 0 评论 -
chapter6 分支语句
// if.cpp -- using the if statement#include <iostream>#include <fstream> int main(){ using namespace std; //6.1if char ch; int spaces = 0; int total = 0; cin.get(ch); while (ch != '.') // quit at end of sentence原创 2020-11-26 16:41:41 · 82 阅读 · 0 评论 -
chapter5循环
// for if wh#include <iostream>#include <string>#include <ctime>int main(){ using namespace std; //5.1for string word = "fdsfsdf";// physically modify string object char temp; int i, j; for (j = 0, i = word.size() - 1; j < i原创 2020-11-26 14:31:20 · 63 阅读 · 0 评论 -
chapter4 复合类型
chapter4 复合类型// addpntrs.cpp -- pointer addition#include <iostream>#include <string> // make string class available#include <cstring> // C-style string libraryint main(){ //array using namespace std; in原创 2020-11-25 16:32:41 · 76 阅读 · 0 评论 -
chapter3 类型与变量
chapter3 类型与变量// floatnum.cpp -- floating-point types#include <iostream>int main(){ using namespace std; cout.setf(ios_base::fixed, ios_base::floatfield); // 保留结尾的0 float tub = 10.0 / 3.0; // 精确到第六位 double mint = 10.0 / 3.0;原创 2020-11-24 17:12:38 · 84 阅读 · 0 评论 -
chapter2 start cpp
chapter2 start cpp#include <iostream> // 预处理器将iostream文件添加到程序中, //将其内容随原代码文件的内容一起被发送给编译器int main() // function header{ // start of原创 2020-11-23 14:20:51 · 127 阅读 · 0 评论 -
chapter17文件
chapter17文件#1.append//该程序维护一个储存来客清单的文件// append.cpp -- appending information to a file#include <iostream>#include <fstream>#include <string>#include <cstdlib> // (or stdlib.h) for exit()const char * file = "guests.txt"原创 2020-11-23 10:39:40 · 117 阅读 · 0 评论 -
16.string类和标准库
161.string输入智能ptr3.stlvector// vect3.cpp -- using STL functions#include <iostream>#include <string>#include <vector>#include <algorithm>struct Review { std::string title; int rating;};bool operator<(const原创 2020-10-31 15:19:39 · 95 阅读 · 0 评论