#include "stdafx.h"
#include <iostream>
using namespace std;
void f(int **p1)
{
int a=5;
*p1 = &a;
cerr<<"a的地址是"<<&a<<endl;
}
void g( void)
{
int *x = NULL;
f(&x);
cerr<<"x的地址是"<<x<<endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
g();
return 0;
}
我在g函数中定义了一个空指针x,我想让它指向一个地址。但是这个地址是f 函数产生的,于是采用这种指针的方式进行调用,可以达到我们想要的效果。这中方法我最先在opencv给的示例代码中看到的。那里面的f函数产生了很大的数据块。
参考文献:http://www.oschina.net/code/explore/OpenCV-2.1.0/samples/c/letter_recog.cpp