C++三级指针传址调用

来源:互联网 发布:增长率算法 编辑:程序博客网 时间:2024/06/07 22:55
//这是技术交流群中一哥们问到的 实际中这么写肯定很2的 属于没事找抽型的

class A{public: void OutPut(){ cout<<"保存的数字 = "<<nTest<<endl; } void SetNum( int num ) { nTest = num; }private: int nTest;};void Test(A ***p1,A ***p2){ //**p1  = new A(); //(**p1)->SetNum(10); A *p = new A(); p->SetNum(10); *(*p1) = p; p = new A(); p->SetNum(15); **p2 = p;}int _tmain(int argc, _TCHAR* argv[]){ A **p1 = NULL; A **p2 = NULL; A *p3 = NULL; //必须要定义 A *p4 = NULL; //必须要定义 p1 = &p3; p2 = &p4; Test(&p1,&p2); (*p1)->OutPut(); (*p2)->OutPut(); p3->OutPut(); p4->OutPut(); return 0;}

原创粉丝点击