初始化:1 #include //auto_ptr header2 void f()3 {4 auto_ptr ptr(new classA);5 }拷贝:1 //auto_ptr can't be initialized by = operator2 auto_ptr ptr1(new cla.....
分类:
其他好文 时间:
2014-07-22 22:47:14
阅读次数:
198
动态分配的vector指针
vector *get_num(int n)
{
vector *pv = new vector(n+1);
int i , x;
for(i = 0; i >x;
(*pv)[i] = (x);
}
return pv;
}
如果是动态分配的vector...
分类:
其他好文 时间:
2014-07-22 22:38:16
阅读次数:
256
type __sync_fetch_and_add (type *ptr, type value, ...) type __sync_fetch_and_sub (type *ptr, type value, ...) type __sync_fetch_and_or (type *ptr, type value, ...) type __sync_fetch_and_and (type *...
分类:
其他好文 时间:
2014-07-22 09:00:07
阅读次数:
163
shared_ptr智能指针的意思即:boost::shared_ptr是可以智能的管理动态分配的内存资源,几个智能指针可以同时共享一个动态分配的内存的所有权。
下面我们通过一个例子来学习一下它的用法:
注 :使用shared_ptr智能指针,要加入#include 头文件
class example
{
public:
~example() { std::cout "...
分类:
其他好文 时间:
2014-07-21 22:43:47
阅读次数:
297
实际上auto_ptr 只是C++标准库提供的一个类模板,它与传统的new/delete控制内存相比有一定优势,使用它不必每次都手动调用delete去释放内存。当然有利也有弊,也不是完全完美的。
本文从下面的8个方面来总结auto_ptr使用的大部分内容。
1. auto_ptr是什么?
auto_ptr 是C++标准库提供的类模板,auto_ptr对象通过初始化指向由new创建的动态内存,...
分类:
编程语言 时间:
2014-07-21 22:22:38
阅读次数:
276
#include
main()
{
int a[3][4],*ptr;
int i,j;
ptr=a[0];
for(i=0;i
for(j=0;j
scanf("%d",ptr++); //指针的表示方法
ptr=a[0];
for(i=0;i
{...
分类:
其他好文 时间:
2014-07-21 11:16:34
阅读次数:
165
方法一:数组法——用a[i]形式法访问数组元素
#include
int main()
{
int i,a[10],*ptr=a;
for(i=0;i
scanf("%d",&a[i]);
for(i=0;i
printf("%4d",a[i]);
printf("\n");
}
方法二:指针法——用*(ptr+i)形式...
分类:
其他好文 时间:
2014-07-21 11:14:14
阅读次数:
171
对于tr1::shared_ptr在安装vs同时会自带安装,但是版本较低的不存在。而boost作为tr1的实现品,包含
“Algorithms
Broken Compiler Workarounds
Concurrent Programming
Containers
Correctness and Testing
Data Structures
Domain Specific
Fu...
分类:
其他好文 时间:
2014-07-19 23:18:19
阅读次数:
371
c汇编 例子程序如下:#include int main(){int arr[] = {6,7,8,9,10};int * ptr = arr;*(ptr++) += 123;printf("%d, %d\n",*ptr,*(++ptr));return 0;}一开始,指针ptr指向第一个元素6,....
分类:
其他好文 时间:
2014-07-19 14:16:26
阅读次数:
278
测试环境:win7, vs2012如果未安装boost,请参考:http://blog.csdn.net/alex_my/article/details/17630685涉及智能指针:shared_ptr, weak_ptr, scoped_ptr, auto_ptr其它:enable_shared...
分类:
编程语言 时间:
2014-07-19 14:15:45
阅读次数:
276