传递指针的引用

来源:互联网 发布:铣床数控编程程序简历 编辑:程序博客网 时间:2024/05/02 21:11

简单的说,跟传递指向指针的指针带来的效果类似。目的是改变指针的指向(单纯传指针只能改变指向区域的内容),也就是传引用带来的效果。

一个小例子,调用fuc()输出的是30,即改变了参数指针的指向;调用fuc2()输出的还是2。

#include "StdAfx.h"#include <iostream>using namespace std;int *b = new int;void fuc(int *&a){a = b;}void fuc2(int *a){a = b;}void main(){int *test = new int;*test = 2;*b = 30;//fuc2(test);fuc(test);cout<<*test<<endl;system("pause");}




原创粉丝点击