摘要:
拷贝构造函数一个构造函数的第一个参数是自身类类型的引用,额外的参数(如果有)都有默认值,那么这个构造函数是拷贝构造函数。拷贝构造函数的第一个参数必须是一个引用类型。合成的拷贝构造函数 在我们没有定义自己的拷贝构造函数,编译器会为我们合成一个。但是对于有些类来说,合成拷贝构造函数用来阻止我们拷贝该类类... 阅读全文
2015年9月2日
2015年8月30日
摘要:
原文链接:点击打开链接用栈实现下列队列操作:push(x) 在队列末尾添加元素xpop() 删除队列首的元素peek() 返回队列首元素但不删除它empty() 判断队列是否为空struct Queue { int data; struct Queue* next;};typede... 阅读全文
摘要:
C++ Primer书上这个例子讲的很不错,写写帮助自己理解标准库和智能指针。.h 文件内容#include #include #include #include #include #include #include #include class QueryResult;class TextQuer... 阅读全文
2015年8月27日
摘要:
标准库allocator类定义在头文件 中。它帮助我们将内存分配和构造分离开来,它分配的内存是原始的、未构造的。类似vector,allocator也是一个模板类,我们在定义一个allocator类类型的时候需要制定它要分配内存的类型,它会根据给定的对象类型来确定恰当的内存大小和对齐位置:alloc... 阅读全文
摘要:
动态数组的分配和释放new和数组C++语言和标准库提供了一次分配一个对象数组的方法,定义了另一种new表达式语法。我们需要在类型名后跟一对方括号,在其中指明要分配的对象的数目。int* arr = new int[20]; // arr 指向第一个int方括号中的大小必须是整数,但不必是常量。可以使... 阅读全文
2015年8月26日
摘要:
unique_ptr一个unique_ptr拥有它所管理的对象,与shared_ptr不同,unique_ptr指向的对象只能有一个用户。当unique_ptr被销毁后,它所指向的对象也被销毁。定义一个unique_ptr时,需要将其绑定到一个new返回的指针上,类似shared_ptr,初始化un... 阅读全文
摘要:
原文链接:点击打开链接Reverse a singly linked listA linked list can be reversed either iteratively or recursively. Could you implement both?struct ListNode* reve... 阅读全文
摘要:
单链表头文件 Link_list.h#pragma once#include #include #include struct Node{ int Element; struct Node* Next;};typedef struct Node* List;typedef st... 阅读全文
摘要:
原文链接:点击打开链接原题是这样的:Given a linked list and a valuex, partition it such that all nodes less thanxcome before nodes greater than or equal tox.You should ... 阅读全文
摘要:
shared_ptr和new结合使用一个shared_ptr默认初始化为一个空指针。我们也可以使用new返回的指针来初始化一个shared_ptr:shared_ptr p1;shared_ptr p2(new int(42)); // p2指向一个值为42的int接受指针参数的智能指针构造函数是e... 阅读全文