上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 46 下一页
摘要: 在C++模板中的类型参数一般可以使用typename和class,两者没有什么不同。但是typename比class多项功能:“任何时候当你想要在template中指涉一个嵌套从属类型名称,就必须在其前面加上关键字typename”因为C++默认情况下把属性都作为值来看待而不是类型。#include... 阅读全文
posted @ 2014-12-23 14:44 卖程序的小歪 阅读(211) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std;class Base { public: int add(int a, int b) { return a + b; }};class Derived : public... 阅读全文
posted @ 2014-12-23 11:03 卖程序的小歪 阅读(100) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std;int add(int a, int b) { return a + b;}int main() { function f = add; cout fsingle = bind(add, 1... 阅读全文
posted @ 2014-12-23 10:41 卖程序的小歪 阅读(123) 评论(0) 推荐(0) 编辑
摘要: #include #include using namespace std;class Pen {public: virtual void write(int color = 0) { coutwrite(); return 0;}输出:write with col... 阅读全文
posted @ 2014-12-22 21:17 卖程序的小歪 阅读(276) 评论(0) 推荐(0) 编辑
摘要: 以书上的代码为例processWidget(shared_ptr(new Widget), priority())虽然使用了智能指针来管理资源但是,由于参数值计算顺序的不确定性,new智能并不一定立刻在priority之前初始化了智能指针,这样如果priority抛出异常,资源就泄露了。。。 阅读全文
posted @ 2014-12-21 22:03 卖程序的小歪 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 15. 智能指针可以通过get操作#include #include #include using namespace std;class Orange {private: int weight;public: Orange(int w) : weight(w) {} int ge... 阅读全文
posted @ 2014-12-21 21:47 卖程序的小歪 阅读(140) 评论(0) 推荐(0) 编辑
摘要: #include #include #include using namespace std;class Kiwi {private: int weight;public: Kiwi(int w) : weight(w) {} ~Kiwi() { cout p(new... 阅读全文
posted @ 2014-12-21 21:08 卖程序的小歪 阅读(312) 评论(0) 推荐(0) 编辑
摘要: #include #include #include using namespace std;class Kiwi {private: int weight;public: Kiwi(int w) : weight(w) {} ~Kiwi() { cout p(new... 阅读全文
posted @ 2014-12-21 20:33 卖程序的小歪 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 当我们自己编写拷贝构造函数时,编译器就不会为该类生成默认拷贝构造函数了,对于assignment operator也是如此。1. 拷贝构造函数中记得调用父类的拷贝构造函数,或者相应复制过程class Man {private: int age;public: Man(int _age =... 阅读全文
posted @ 2014-12-21 20:07 卖程序的小歪 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 1. 返回一个reference to *this返回一个指向自身的引用符合惯例,可以进行如(a=c).modify()类似的操作,即可以形成链式操作,否则修改的只是一个临时对象。这个和Java中常用的builder模式是一个道理2. 自我赋值的检测和异常安全赋值进行前进行自我检测,相同就直接返回。... 阅读全文
posted @ 2014-12-21 19:30 卖程序的小歪 阅读(229) 评论(0) 推荐(0) 编辑
上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 46 下一页