W
WaterWalk
(Sorry if I duplicated this post. My previous post somehow
disappeared.)
Hello. I am rather confused about pointers to class data members. Take
the following class as an example:
class MyClass
{
public:
int n;
};
I can use the pointer-to-member syntax to access MyClass::n:
typedef int MyClass*pn_t;
pn_t pn = &MyClass::n;
MyClass my;
my.*pn = 123;
But at the same time, the common pointer-to-data also seems to work:
MyClass my;
int *pn = &my.n;
*pn = 123;
I don't know if the second method is legal in c++ standard. If it is,
why bother to have the first method?
disappeared.)
Hello. I am rather confused about pointers to class data members. Take
the following class as an example:
class MyClass
{
public:
int n;
};
I can use the pointer-to-member syntax to access MyClass::n:
typedef int MyClass*pn_t;
pn_t pn = &MyClass::n;
MyClass my;
my.*pn = 123;
But at the same time, the common pointer-to-data also seems to work:
MyClass my;
int *pn = &my.n;
*pn = 123;
I don't know if the second method is legal in c++ standard. If it is,
why bother to have the first method?