上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 29 下一页
摘要: 多线程下的内存管理与单线程下是完全不同的,因为heap是一个可以被全局改动的资源,所以所有的线程都有可能去访问这一资源,这回导致很多的race_conditions。当operator new未取得想要的内存的时候,会调用一个用户指定的处理函数,new_handler。 这个函数可以使用set_ne... 阅读全文
posted @ 2015-10-18 17:14 eversliver 阅读(564) 评论(0) 推荐(0) 编辑
摘要: 1 void adance(std::list::iterator& iter, int d) 2 { 3 if(typeid(std::iterator_traits::iterator>::iterator_catagory) 4 ]== typeid(std::ra... 阅读全文
posted @ 2015-10-18 17:13 eversliver 阅读(283) 评论(0) 推荐(0) 编辑
摘要: 在stl的算法中,我们的希望往往是根据不同的迭代器类型进行不同的更有效率的操作: 1 template 2 void advance(IterT iter, DistT dis) 3 { 4 if(iter is a random access iterator) 5 ite... 阅读全文
posted @ 2015-10-18 17:12 eversliver 阅读(402) 评论(0) 推荐(0) 编辑
摘要: 看看下面这个例子: 1 template 2 class Rational{ 3 public: 4 Rational(const T & numerator, const T & denominator); 5 const T numerator()const; 6 con... 阅读全文
posted @ 2015-10-18 17:08 eversliver 阅读(417) 评论(0) 推荐(0) 编辑
摘要: 首先看看下面的真实的指针与模板创建的智能指针之间的区别:1 class Top{...};2 class Middle : public Top{...};3 class Bottom : public Middle{...};4 Top * p1 = new Bottom();5 Top * p2... 阅读全文
posted @ 2015-10-18 17:07 eversliver 阅读(291) 评论(0) 推荐(0) 编辑
摘要: 使用template时,不小心的时候可能就会带来代码膨胀的问题:1 template3 class SquareMatrix{4 public:5 void invert();6 };7 //而对于下面两份模版实例化8 SquareMatrix ma10;9 SquareMatrix ma5... 阅读全文
posted @ 2015-10-18 17:05 eversliver 阅读(380) 评论(0) 推荐(0) 编辑
摘要: typename在很多种情况下与class是完全相同的,例如下面的使用:1 templame2 ......3 template4 ......条款42:了解typename的双重含义 1 template 2 void print2nd(const C containter) 3 { 4 ... 阅读全文
posted @ 2015-10-18 17:03 eversliver 阅读(319) 评论(0) 推荐(0) 编辑
摘要: 相对于继承体系来说,template实际上也使用接口与多态,而继承体系往往使用到的是显式接口以及运行期多态,而template实际上用的是隐式接口以及编译期多态。隐式接口实际上就是类似下面这样的东西:1 template 2 int myTypes(T & tmp)3 {4 tmp.size... 阅读全文
posted @ 2015-10-18 17:02 eversliver 阅读(272) 评论(0) 推荐(0) 编辑
摘要: 多重继承很容易带来的一个问题就是歧义的问题: 1 class BorrowAble{ 2 public: 3 void checkOut() const; 4 ... 5 }; 6 class ElectronicGadget{ 7 private: 8 bool check... 阅读全文
posted @ 2015-10-18 17:00 eversliver 阅读(249) 评论(0) 推荐(0) 编辑
摘要: 首先看一下private继承的法则:class之间的继承关系如果是private的话,那么编译器不会将一个derived对象自动当作为一个base class对象。从base class继承而来的所有方法以及属性,在derived class都会变成是private的。private继承的底层含义实... 阅读全文
posted @ 2015-10-18 16:59 eversliver 阅读(212) 评论(0) 推荐(0) 编辑
上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 29 下一页