Greetings all,
Please take a look at following code:
#include <stdio.h>
#include <iostream>
using namespace std;
typedef struct MyType{
int num1;
};
void test(MyType **src)
{
MyType *ret=new MyType;
ret->num1=666;
*src=ret;
}
int main(){
MyType *mSrc;
test(&mSrc);
printf("%d Address\n",mSrc);
printf("%d Value \n",mSrc->num1);
}
I am wondering if the test() method had been implemented as follows,why the pointer assignment inside test() method is not visible to the caller?
void test(MyType *src)
{
MyType *ret=new MyType;
ret->num1=666;
src=ret; //Why this assignment is only valid inside this method?
}
How do I implement this function without using a double pointer in the signature?