What are pointers to class members used for?
Posted
by srikfreak
on Stack Overflow
See other posts from Stack Overflow
or by srikfreak
Published on 2010-05-06T05:06:20Z
Indexed on
2010/05/06
5:08 UTC
Read the original article
Hit count: 342
I have read about pointers to class members, but I have never seen them being used in any practical applications. Can someone explain what are the use cases of such pointers? Is it really necessary to have such pointers?
Eg.
class abc
{
public:
int a;
abc(int val) { a = val; }
};
int main
{
int abc::*data;
abc obj(5);
data = &abc::a;
cout << "Value of a is " << obj.*data << endl;
return 0;
}
In the above eg. why is the value of 'a' accessed in this manner? What is the advantage of using pointers to class members?
© Stack Overflow or respective owner