随笔分类 -  c++

摘要:template class ObjectPool { public: using DeleterType = std::function; void add(std::unique_ptr t) { std::lock_guard locker(mutex_); pool_.push_back(std::move(t)); }... 阅读全文
posted @ 2017-11-02 20:23 略加思索的河马 阅读(169) 评论(0) 推荐(0) 编辑
摘要:#define TEST(ITEMNAME) AddItem(ITEMNAME, #ITEMNAME); template void AddItem(T& var, const std::string& name) { cout void foo_impl(T val, true_type) { cout void foo_impl(T val, false_type) ... 阅读全文
posted @ 2017-09-22 09:56 略加思索的河马 阅读(174) 评论(0) 推荐(0) 编辑
摘要://////////////////////////////////////////////////////////////////////////////// template class message_server_indie : public nocopyable { public: typedef message_queue > message_queue_alias; ///... 阅读全文
posted @ 2017-04-20 11:18 略加思索的河马 阅读(311) 评论(0) 推荐(0) 编辑
摘要:类型转换函数 operator 目标类型() { ... return 目标类型的数据; } 阅读全文
posted @ 2017-03-13 13:35 略加思索的河马 阅读(303) 评论(0) 推荐(0) 编辑
摘要:1.类成员函数中const变量的初始化(也就是第一点) 有几个容易混淆的地方: (1)const 的变量只能通过构造函数的初始化列表进行初始化;(貌似在C++11中可以正常编译) (2)static 的变量只能通过在类外重新定义进行初始化; (3)static const 变量 只能通过在类中直接用 阅读全文
posted @ 2017-03-09 16:57 略加思索的河马 阅读(1282) 评论(0) 推荐(0) 编辑
摘要:用法:dynamic_cast < type-id > ( expression ) 说明:Type-id必须是类的指针、类的引用或者void *;如果type-id是指针类型,那么expression也必须是一个指针,如果type-id是一个引用,那么expression也必须是一个引用。 dyn 阅读全文
posted @ 2017-02-21 17:23 略加思索的河马 阅读(281) 评论(0) 推荐(0) 编辑
摘要:1. inline是实现修饰符,而非声明修饰符,所以应该用于实现部分的修饰(你也可以放置inline在声明,但是没有必要) 2. 所有中类中定义的函数都默认声明为inline函数,所有我们不用显示地去声明inline。 3. 建议把inline函数的定义放到头文件中,这种方法保证对每个inline函 阅读全文
posted @ 2017-01-13 11:38 略加思索的河马 阅读(259) 评论(0) 推荐(0) 编辑
摘要:#ifndef _QSHAREPTR_H #define _QSHAREPTR_H #include "Utility.h" namespace Q_COMMON{ template class QSharePtr { public: class PointerCount { private: long refCount; T* ob... 阅读全文
posted @ 2016-08-24 09:02 略加思索的河马 阅读(168) 评论(0) 推荐(0) 编辑
摘要:首先,任何虚拟基类的构造函数按照它们被继承的顺序构造; 其次,任何非虚拟基类的构造函数按照它们被继承的顺序构造; 最后,任何成员对象的构造函数按照它们声明的顺序调用; 阅读全文
posted @ 2016-06-07 17:49 略加思索的河马 阅读(215) 评论(0) 推荐(0) 编辑
摘要:1. 函数模板 普通函数 void Swap(int &, int &); 模板函数 template void Swap(T &, T &); 显示具体化,下面两个等价 template void Swap(int &, int &); template void Swap(int &, int &); 注意:具体化将覆盖模板函数,普通函数将覆盖具体化和模板函数。 ... 阅读全文
posted @ 2016-05-07 17:36 略加思索的河马 阅读(214) 评论(0) 推荐(0) 编辑
摘要:  阅读全文
posted @ 2016-03-13 21:19 略加思索的河马 阅读(415) 评论(0) 推荐(0) 编辑
摘要:const int MaxObjectNum = 10; template <typename T> class ObjectPool { template <typename... Args> using Constructor = std::function<std::shared_ptr<T> 阅读全文
posted @ 2016-03-12 00:15 略加思索的河马 阅读(897) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <string> using namespace std; template <typename T> void PrintT(T& t) { cout << "lvalue" << endl; } template <typename T> 阅读全文
posted @ 2016-03-09 18:36 略加思索的河马 阅读(255) 评论(0) 推荐(0) 编辑
摘要:unordered_map和map类似,都是存储的key-value的值,可以通过key快速索引到value。 不同的是unordered_map不会根据key的大小进行排序,存储时是根据key的hash值判断元素是否相同,即unordered_map内部元素是无序的,而map中的元素是按照二叉搜索 阅读全文
posted @ 2016-02-23 09:09 略加思索的河马 阅读(253) 评论(0) 推荐(0) 编辑
摘要:文件名 InstInterfaceDef.h #ifndef FUANDA_WORKPLAN_INST_INTERFACE_DEF_H_#define FUANDA_WORKPLAN_INST_INTERFACE_DEF_H_ #pragma pack(push,1) /*指定1字节对齐*/ #pr 阅读全文
posted @ 2015-10-16 13:41 略加思索的河马 阅读(981) 评论(0) 推荐(1) 编辑

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