随笔分类 - C++
摘要:#include <iostream> #include <tuple> int main() { std::tuple<int, char, float> tuple; tuple = std::make_tuple(18, 'a', 2.5); int a; char b; float c; s
阅读全文
摘要:编写结构 // Filename: person.proto syntax="proto3"; package person; message Person { string name = 1; int32 id = 2; uint32 age = 3; enum PhoneType { MOBIL
阅读全文
摘要:Protocol Buffers是一种轻便高效的结构化数据存储格式,可以用于结构化数据串行化,或者说序列化 https://github.com/protocolbuffers/protobuf.git 编译 # apt-get install autoconf automake libtool c
阅读全文
摘要:#include <iostream> #include <memory> using namespace std; class Person { public: Person() { cout << "Person()构造" << endl; } ~Person() { cout << "~Per
阅读全文
摘要:无序map容器 对于有顺序要求的问题,map会更高效一些 对于查找问题,unordered_map会更加高效一些 #include <iostream> #include <unordered_map> int main() { std::unordered_map<int, std::string
阅读全文
摘要:assert是运行期断言,它用来发现运行期间的错误 stastic_assert为了弥补assert和error的不足,可以作编译期的静态检查 #include <iostream> int main() { static_assert(sizeof(char) == 2, "hello furon
阅读全文
摘要:#include <iostream> #include <memory> using namespace std; class Person { public: Person() { cout << "Person()构造" << endl; } ~Person() { cout << "~Per
阅读全文
摘要:default(Defaulted Function) 编译器创建此函数的默认实现 默认函数需要用于特殊的成员函数(默认构造函数,复制构造函数,析构函数等) delete(expicitly deleted) 禁用成员函数使用 通常是针对隐式函数 class A { public: A() = de
阅读全文
摘要:Code::Blocks Dev-C++ clion C-Free
阅读全文
摘要:至少有一个纯虚函数 不能生成对象 模拟方法 构造和拷贝构造都使用protected修饰 析构函数设置为纯虚函数 析构函数使用protected修饰
阅读全文
摘要:#include <iostream> using namespace std; void func(int a) { if(a == 0) { throw string("a is error"); throw a; } } int main() { try { func(0); } catch(
阅读全文
摘要:#include <iostream> #include <typeinfo> int main() { int i; const std::type_info &info = typeid(int); std::cout << "typeid " << info.name() << std::en
阅读全文
摘要:#include <iostream> class Base { public: Base() { func(); } ~Base() { func(); } virtual void func() { std::cout << "Base func" << std::endl; } }; clas
阅读全文
摘要:#include <iostream> #include <thread> #include <mutex> std::timed_mutex mutex; void mythread() { std::chrono::milliseconds timeout(100); //100ms std::
阅读全文
摘要:原子操作指“不可分割的操作”,一般针对一个变量 互斥量一般针对代码段 #include <iostream> #include <thread> #include <atomic> std::atomic<int> atomic; void add() { for(int i = 0; i < 10
阅读全文
摘要:#include <iostream> #include <future> int mythread() { std::cout << "mythread " << std::this_thread::get_id() << std::endl; std::chrono::milliseconds
阅读全文
摘要:#include <iostream> #include <future> int mythread() { std::cout << "mythread " << std::this_thread::get_id() << std::endl; std::chrono::milliseconds
阅读全文
摘要:#include <iostream> #include <future> void mythread(std::promise<int> &promise, int arg) { std::cout << "mythread " << std::this_thread::get_id() << s
阅读全文
摘要:#include <iostream> #include <future> int mythread(int arg) { std::cout << "mythread " << std::this_thread::get_id() << std::endl; std::cout << "arg "
阅读全文
摘要:#include <iostream> #include <future> int mythread() { std::cout << "mythread " << std::this_thread::get_id() << std::endl; std::chrono::milliseconds
阅读全文