C++工作笔记-对二级指针的进一步理解(获取调用者的地址)

一般的项目中,如果要获取调用者参数的地址可以考虑使用二级指针。

程序运行截图如下:

源码如下:

#include <iostream>
#include <conio.h>
using namespace std;

class A {
public:
	void print() {
		cout << "Class A print called!\n";
	}
};

void analyseParameter(A **a) {
	cout << "The &a is " << &a << endl;
	cout << "The a is " << a << endl;
	cout << "The *a is " << *a << endl;
}

void main() {
	A *myA = new A;
	myA->print();
	cout << "The myA address is " << &myA << endl;
	analyseParameter(&myA);
	_getch();
}

可以发现,直接把&myA传过去,用二级指针接收,就完事了!!!!!!!!

感觉这方法有点歪门邪道!!!!

猜你喜欢

转载自blog.csdn.net/qq78442761/article/details/81325146