Top.Mail.Ru
The C++ Community's Journal -- Day
? ?
The C++ Community's Journal -- Day [entries|friends|calendar]
The C++ Community

[ userinfo | livejournal userinfo ]
[ calendar | livejournal calendar ]

Real-world use for a function returning a pointer to a class data member? [24 Aug 2005|10:47pm]
A friend of mine - a computer engineer working in the industry - IM'd me today with some questions about some code he was working with. One thing he asked me about was a function that returns a pointer to a class data member. Now, I completely see the purpose of a pointer to a class member function, but the only uses I can imagine for a pointer to a class data member are completely artificial ones; I can't think of a real-world use for such a thing. So, anyone care to enlighten me? :-)

ETA: Maybe the terminology isn't as standard as I thought, or maybe it's just that the terminology is confusing, but to clarify: by a "pointer to a class data member," I mean an actual pointer-to-a-class-data-member type; the function is prototyped as something like A B::* f(), and its return value would be dereferenced using something like instance_of_B.*(f()). That is, it doesn't return a pointer to a data member of a specific instance of the class; rather, it returns a pointer to a data member of the class as a whole, and this pointer can be dereferenced using an instance of the class.

Thank you to everyone who's replied so far. :-)
13 comments|post comment

navigation
[ viewing | August 24th, 2005 ]
[ go | previous day|next day ]
Image