C++11
huyanjie0327
这个作者很懒,什么都没留下…
展开
-
右值引用
我们写代码的时候,总会遇到下面的情况:class Obj {};Obj getObj() { Obj obj; // 创建临时变量 // some initialize code for obj return obj; // 返回一个临时变量}int main() { Obj obj = getObj(); // 这里会将返回值赋值给obj}原创 2015-06-24 16:31:47 · 254 阅读 · 0 评论 -
用boost::shared_ptr 进行数据管理
我们经常遇到这样的情况, 类A和类B同时需要使用类C这个数据。那么类C这个数据由谁来存储呢?比如:有个Student A, Class C(班级), Student Union SU(学生会), 这个学生A既可能是班级C的一员,也可能是学生会SU的一员。下面是一个demo。#include #include #include #include class Student{p原创 2015-08-10 18:04:03 · 365 阅读 · 0 评论 -
Service 写法
写了一个简单的service原创 2015-08-11 19:13:57 · 572 阅读 · 0 评论 -
C++ Read a whole File using ifstream
std::ifstream ifs("filename.txt");std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator());Mind the extra parenthesis in the str declaration, it's necessary for correct p原创 2015-08-17 20:16:55 · 472 阅读 · 0 评论 -
智能指针创建多叉树
参考:http://thispointer.com/shared_ptr-binary-trees-and-the-problem-of-cyclic-references/#include #include #include using namespace std;class Node : public enable_shared_from_this{public: typ原创 2015-11-04 14:09:08 · 418 阅读 · 0 评论 -
方便的类成员访问接口
对于含有许多数据成员的类, 通常需要提供数据的set和get接口,下面的代码提供了一种set和get的形式,接口比较简洁:#include #include #include using namespace std;class Person{public:Person(const string& name, int age) :mName原创 2015-11-04 14:24:36 · 310 阅读 · 0 评论