随笔分类 -  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 阅读全文
posted @ 2023-01-31 13:36 thomas_blog 阅读(32) 评论(0) 推荐(0) 编辑
摘要:编写结构 // Filename: person.proto syntax="proto3"; package person; message Person { string name = 1; int32 id = 2; uint32 age = 3; enum PhoneType { MOBIL 阅读全文
posted @ 2022-09-12 14:36 thomas_blog 阅读(27) 评论(0) 推荐(0) 编辑
摘要:Protocol Buffers是一种轻便高效的结构化数据存储格式,可以用于结构化数据串行化,或者说序列化 https://github.com/protocolbuffers/protobuf.git 编译 # apt-get install autoconf automake libtool c 阅读全文
posted @ 2022-09-11 23:35 thomas_blog 阅读(168) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <memory> using namespace std; class Person { public: Person() { cout << "Person()构造" << endl; } ~Person() { cout << "~Per 阅读全文
posted @ 2022-09-06 21:04 thomas_blog 阅读(194) 评论(0) 推荐(0) 编辑
摘要:无序map容器 对于有顺序要求的问题,map会更高效一些 对于查找问题,unordered_map会更加高效一些 #include <iostream> #include <unordered_map> int main() { std::unordered_map<int, std::string 阅读全文
posted @ 2022-09-05 18:41 thomas_blog 阅读(74) 评论(0) 推荐(0) 编辑
摘要:assert是运行期断言,它用来发现运行期间的错误 stastic_assert为了弥补assert和error的不足,可以作编译期的静态检查 #include <iostream> int main() { static_assert(sizeof(char) == 2, "hello furon 阅读全文
posted @ 2022-09-02 16:47 thomas_blog 阅读(62) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <memory> using namespace std; class Person { public: Person() { cout << "Person()构造" << endl; } ~Person() { cout << "~Per 阅读全文
posted @ 2022-09-02 16:06 thomas_blog 阅读(20) 评论(0) 推荐(0) 编辑
摘要:default(Defaulted Function) 编译器创建此函数的默认实现 默认函数需要用于特殊的成员函数(默认构造函数,复制构造函数,析构函数等) delete(expicitly deleted) 禁用成员函数使用 通常是针对隐式函数 class A { public: A() = de 阅读全文
posted @ 2022-09-01 15:13 thomas_blog 阅读(74) 评论(0) 推荐(0) 编辑
摘要:Code::Blocks Dev-C++ clion C-Free 阅读全文
posted @ 2022-08-25 19:34 thomas_blog 阅读(23) 评论(0) 推荐(0) 编辑
摘要:至少有一个纯虚函数 不能生成对象 模拟方法 构造和拷贝构造都使用protected修饰 析构函数设置为纯虚函数 析构函数使用protected修饰 阅读全文
posted @ 2022-08-25 13:31 thomas_blog 阅读(18) 评论(0) 推荐(0) 编辑
摘要:#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( 阅读全文
posted @ 2022-08-19 08:41 thomas_blog 阅读(15) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <typeinfo> int main() { int i; const std::type_info &info = typeid(int); std::cout << "typeid " << info.name() << std::en 阅读全文
posted @ 2022-08-17 08:40 thomas_blog 阅读(30) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> class Base { public: Base() { func(); } ~Base() { func(); } virtual void func() { std::cout << "Base func" << std::endl; } }; clas 阅读全文
posted @ 2022-08-17 07:48 thomas_blog 阅读(19) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <thread> #include <mutex> std::timed_mutex mutex; void mythread() { std::chrono::milliseconds timeout(100); //100ms std:: 阅读全文
posted @ 2022-08-13 13:16 thomas_blog 阅读(72) 评论(0) 推荐(0) 编辑
摘要:原子操作指“不可分割的操作”,一般针对一个变量 互斥量一般针对代码段 #include <iostream> #include <thread> #include <atomic> std::atomic<int> atomic; void add() { for(int i = 0; i < 10 阅读全文
posted @ 2022-08-11 19:17 thomas_blog 阅读(327) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <future> int mythread() { std::cout << "mythread " << std::this_thread::get_id() << std::endl; std::chrono::milliseconds 阅读全文
posted @ 2022-08-08 19:12 thomas_blog 阅读(93) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <future> int mythread() { std::cout << "mythread " << std::this_thread::get_id() << std::endl; std::chrono::milliseconds 阅读全文
posted @ 2022-08-08 18:47 thomas_blog 阅读(655) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <future> void mythread(std::promise<int> &promise, int arg) { std::cout << "mythread " << std::this_thread::get_id() << s 阅读全文
posted @ 2022-08-08 16:25 thomas_blog 阅读(268) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <future> int mythread(int arg) { std::cout << "mythread " << std::this_thread::get_id() << std::endl; std::cout << "arg " 阅读全文
posted @ 2022-08-08 15:41 thomas_blog 阅读(40) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <future> int mythread() { std::cout << "mythread " << std::this_thread::get_id() << std::endl; std::chrono::milliseconds 阅读全文
posted @ 2022-08-08 14:55 thomas_blog 阅读(111) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示