目录:1.std::share_ptr智能指针:2.std::tr1::function模板类:3.stringstream:4.set/vector/map:5.static_cast (expression);std::share_ptr智能指针:http://en.cppreference.c...
分类:
编程语言 时间:
2015-12-27 17:41:57
阅读次数:
292
昨晚有小伙伴问了一道题,感觉挺经典的。 1 int a[5] = {1, 2, 3, 4, 5};2 3 int *ptr = (int *) (&a + 1);4 5 printf("%d %d \n\r", *(a + 1), *(ptr - 1) );从内存分布的角度来解析:&a和a做右值时....
分类:
编程语言 时间:
2015-12-27 13:25:48
阅读次数:
298
1.分配空间2.记录内存块信息3.调用构造函数(类型萃取)#include<iostream>
#include<string>
#include<list>
#include<assert.h>
usingnamespacestd;
structBlockInfo
{
void*_ptr;
string_file;
int_line;
BlockInfo(void*ptr,constchar*file,in..
分类:
其他好文 时间:
2015-12-26 23:52:18
阅读次数:
387
unique_ptr的成员函数在上一篇博客中几乎全部涵盖,其实还有一个很有踢掉,即std::unique_ptr::get_deleter字面已经很明显了,就获得deleter:
Returns the stored deleterThe stored deleter is a callable object. A functional call to this object with a sin...
分类:
编程语言 时间:
2015-12-26 13:29:22
阅读次数:
491
既然打算把unique_ptr写一个系列,就要详尽一点,有些内容也许在vector的时候有个涉及,但是现在还是再谈论一番。我们要把unique_ptr看做一个类,废话了,它当然是一个类。所以这个类肯定也重载了赋值运算符,即operator=。现在就开始看看operator=在unique_ptr中的使用:
官方描述如下:move assignment (1)
unique_ptr& operat...
分类:
编程语言 时间:
2015-12-26 01:15:51
阅读次数:
254
说白了就是三个函数的使用:SetTimer(20, 20, 0); //第一个20表示此定时器的标识符,第二个20表示你要定的时间,第三个不用管,设0即可。void CLMS511_interfaceDlg::OnTimer(UINT_PTR nIDEvent){ // TODO: Add your...
分类:
编程语言 时间:
2015-12-25 08:48:21
阅读次数:
368
写了很多篇关于vector的博客,其实vector很便捷,也很简单。但是很多易错的问题都是vector中的元素为智能指针所引起的。所以决定开始写一写关于智能指针的故事,尤其是unique_ptr指针的故事。这是个开始,就让我们使用std::unique_ptr代替new operator吧!还是用程序说话:#include
int main()
{
while (true...
分类:
编程语言 时间:
2015-12-24 23:56:43
阅读次数:
432
之前博客写了对vector使用sort算法进行的排序,之前也写到过vector<unique_ptr>的一些处理方法。今天就写一下对vector<unique_ptr>使用sort算法进行排序。#include
#include
#include
#include
#include<memory...
分类:
编程语言 时间:
2015-12-23 21:27:01
阅读次数:
352
通过考察各种二叉链表,不管儿叉树的形态如何,空链域的个数总是多过非空链域的个数。准确的说,n各结点的二叉链表共有2n个链域,非空链域为n-1个,但其中的空链域却有n+1个。如下图所示。 因此,提出了一种方法,利用原来的空链域存放指针,指向树中其他结点。这种指针称为线索。 记ptr指向二叉链表中...
分类:
其他好文 时间:
2015-12-23 12:27:02
阅读次数:
192
实例用法: 创建对象: class U_Ptr smart; U_Ptr* ptr = new U_Ptr(); class U_Ptr smart(new U_Ptr(p)); int *p = new int; //此时指针p指向一个int对象,该对象没有被初始化 int...
分类:
编程语言 时间:
2015-12-23 12:22:33
阅读次数:
306