// ----------------------------------------
// MyClass definition
#pragma once
class MyClass
{
public:
int Value;
};
typedef MyClass* MyClassPtr;
// ----------------------------------------
// Tester methods
void TestRef(char* i)
{
*i = 'b';
}
void TestNoRef(char i)
{
i = 'c';
}
void TestRef(MyClassPtr* m)
{
(*m)->Value = 10;
}
void TestNoRef(MyClassPtr m)
{
m->Value = 20;
}
void TestCreateRef(MyClassPtr* m)
{
delete (*m);
*m = new MyClass();
(*m)->Value = 100;
}
void TestCreateNoRef(MyClassPtr m)
{
m = new MyClass();
m->Value = 200;
}
int main(int argc, char* argv[])
{
char c = 'a';
TestRef(&c);
printf("%c\n", c); // output: b
TestNoRef(c);
printf("%c\n", c); // output: b
MyClassPtr m = new MyClass;
m->Value = 1;
TestRef(&m);
printf("%d\n", m->Value);
TestNoRef(m);
printf("%d\n", m->Value);
TestCreateRef(&m);
printf("%d\n", m->Value);
TestCreateNoRef(m);
printf("%d\n", m->Value);
delete m;
return 0;
} |