void allocate (int *ptr)
{
ptr = new int(0);
}
void test()
{
int *i=0;
allocate(i);
int k=*i;
cout<<k<<endl;
Release(i);
}
你的allocate传的是一级指针,操作的只是main函数里的i指针的一个拷贝
要改变指针的指向必须要改成一级指针的引用或者二级指针
void allocate (int **ptr)
{
*ptr = new int(0);
}
void test()
{
int *i=0;
allocate(&i);
int k=*i;
cout<<k<<endl;
Release(i);
}