引言: 编写智能指针的要点:a) 构造函数接收堆内存b) 析构函数释放内存c) 必要时要禁止值语义。d) 重载*与->两个操作符 1 #ifndef START_PTR_H 2 #define START_PTR_H 3 4 #include 5 using namespace std; 6 ...
分类:
编程语言 时间:
2014-10-10 03:17:04
阅读次数:
211
char *fun()
{
char str[] = "hello";
return str;
}
这个函数的返回值?以及这个函数在栈上的存储布局
#include
#include
#include
char *fun()
{
char ptr[] = "fda";
int a = 3;
int b = 4; ...
分类:
其他好文 时间:
2014-10-10 00:18:58
阅读次数:
313
段内转移:短转移:jmp short 标号 (IP)=(IP)+8位位移,位移范围-128~127近转移:jmp near ptr 标号 (IP)=(IP)+8位位移,位移范围-32768~32767jmp 16位reg (IP)=(16位reg)jmp word ptr 内存单元地址 ...
分类:
其他好文 时间:
2014-10-09 22:34:27
阅读次数:
169
bind函数在c++11之前,要绑定某个函数、函数对象或者成员函数的不同参数值需要用到不同的转换器,如bind1st、bind2nd、fun_ptr、mem_fun和mem_fun_ref等.在c++11中,绑定参数的方法得以简化.c++11提供了"一站式"绑定模板bind,其用法为:#includ...
分类:
编程语言 时间:
2014-10-09 19:18:07
阅读次数:
252
最简单的智能指针就是将指针封装在类里,同时将该类的复制与赋值禁用,也就是使该类失去值语义。实现代码如下: 1 #ifndef SMART_PTR_H 2 #define SMART_PTR_H 3 #include 4 5 6 template 7 class SmartPtr 8 { 9 ...
分类:
编程语言 时间:
2014-10-09 01:07:37
阅读次数:
327
下面是一个简单的读取PCD文件并显示的代码:#include #include #include #include #include void main(){ /* Create Point Cloud */ pcl::PointCloud::Ptr cloud(new pcl::Poi...
分类:
其他好文 时间:
2014-10-09 00:49:37
阅读次数:
910
#include
typedef int* int_ptr;
typedef unsigned char* byte_ptr;
void show_bytes( byte_ptr start, int len ){
int i;
for( i = 0; i < len; ++i ){
printf( " %4.2x", start[i] );
}
printf( "\n"...
分类:
其他好文 时间:
2014-10-07 13:34:43
阅读次数:
164
int b[8][8]; //int类型数组的数组
int **ptr; //指向int的指针的指针
int *risks[10]; //具有10个元素的数组,每个元素是一个指向int的指针
int (* risk)[10]; //一个指针,指向具有10元素的int数组
int * abc[3][4]; //一个3*4的数组,每个元素都是指向int的指针
in...
分类:
编程语言 时间:
2014-10-06 18:40:20
阅读次数:
213
7.预先准备好内存不够的情况。
new在无法完成内存分配请求时,会抛出异常,异常了要怎么办,这是一个很现实且以后绝对要碰到的问题。
在c中一般使用宏来分配内存并检测分配是否成功,c++中类似以下函数:
#define NEW(PTR,TYPE) try { (PTR) = new TYPE;} catch (std::bad_alloc& ){assert(0);}catc...
分类:
编程语言 时间:
2014-10-06 16:41:30
阅读次数:
174
container_of(ptr,type,member) 用于在已知结构体里面成员member和该成员指针ptr(就是地址)和结构体类型type, 返回该成员所在的结构体的指针(就是地址), 例如已知structstudenta{char*name;intage;}int*page=&age;co...
分类:
其他好文 时间:
2014-10-05 17:43:08
阅读次数:
165