I'm a bit confused on the following two cases. Both functions are passing by pointer. One leads to a change in the main, the other does not. I thought passing by pointer really shouldn't have any effect after the function is called since it produce a local copy of the pointer in the function. Any hints are appreciated
#include <vector>
#include <iostream>
using namespace std;
//
class A
{
public:
int b;
A() {;}
};
//
void test1(A *a)
{
A t;
t.b = 200;
a = &t;
}
//
void test2(A *a)
{
a->b = 200;
}
//
int main()
{
A a;
a.b = 10;
test1(&a);
cout<<"a.b value is NOT changed"<<endl;
cout<<a.b<<endl;
test2(&a);
cout<<"a.b value is changed"<<endl;
cout<<a.b<<endl;
}
//.. the output is:
//a.b value is NOT changed
//10
//a.b value is changed
//200