随笔分类 - C/C++
摘要:什么是线程 注意: ps -Lf (进程名字)可以查看进程的线程 Linux内核实现线程的原理 首先先介绍一下三级页表: 线程创建 注意编译和链接的使用使用 -pthread表示引入线程库 /******************************************************
阅读全文
摘要:#include <iostream> using namespace std; template<class T> class SmartPtr{ public: explicit SmartPtr():ptr(nullptr), count(new int(0)){} explicit Smar
阅读全文
摘要:多线程的栈 #include <iostream> #include <vector> #include <mutex> #include <thread> #include <stack> #include <exception> using namespace std; template<cla
阅读全文
摘要:LRU缓存 struct Node{ int key; int value; Node* next; Node* pre; Node(): key(-1), value(-1), next(nullptr), pre(nullptr){} explicit Node(int key_, int va
阅读全文
摘要:#include <sstream> int main(){ vector<string> arr; string s; getline(cin, s); stringstream ss(s); while(getline(ss, s, ' ')){ arr.push_back(s); } for(
阅读全文
摘要:struct ListNode { int val; ListNode *next; ListNode() : val(0), next(nullptr) {} explicit ListNode(int x) : val(x), next(nullptr) {} ListNode(int x, L
阅读全文
摘要:#include <iostream> using namespace std; #include <set> class Person{ public: Person(string name,int age): name(name),age(age) {} void printInformatio
阅读全文
摘要:1.创建一个Person类 // // Created by Administrator on 2021/7/16. // #ifndef C__TEST01_PERSON_HPP #define C__TEST01_PERSON_HPP template<class T1, class T2> c
阅读全文
摘要:1.继承的构造和析构的顺序 子类继承父类: (1)父类构造函数 (2)子类构造函数 (3)子类析构函数 (4)父类析构函数 不管怎么调用子类结果都是一样的: //通过父类创建子类 Animal *cat = new Cat(); delete cat; cat = NULL; cout<<endl;
阅读全文
摘要:友元函数中成员函数使用 #include <iostream> using namespace std; class BedRoom; //声明一个类 class GoodGay { public: GoodGay(); ~GoodGay(); void visit(); private: BedR
阅读全文
摘要:Father.hpp 1 // 2 // Created by Administrator on 2021/7/15. 3 // 4 5 #ifndef C__TEST01_FATHER_HPP 6 #define C__TEST01_FATHER_HPP 7 8 9 class Father {
阅读全文
摘要:1 // 2 // Created by Administrator on 2021/7/15. 3 // 4 5 #ifndef C__TEST01_PERSON_H 6 #define C__TEST01_PERSON_H 7 8 //类模板 9 template<class T1, class
阅读全文
摘要:1 #include <iostream> 2 using namespace std; 3 4 //常量指针 5 void test01(){ 6 int a = 4; 7 int b = 2; 8 int *const p = &a; 9 cout<<"*p = "<<*p<<endl; 10
阅读全文
摘要:1 #include <iostream> 2 using namespace std; 3 4 //函数的值传递 5 template<typename T> 6 void swapValue(T a, T b){ 7 cout<<"值传递函数开始前a = "<<a<<", "<<"b = "<<
阅读全文
摘要:作用:只产生一个对象 1 class Yoshi { 2 public: 3 //外界只能通过这种方式调用这一个对象,返回必须是引用 4 static Yoshi& getInstance(){return yoshi;} 5 //setup(); 6 private: 7 //两个构造函数 8 Y
阅读全文