* Amadeus W.M.:
I saw somewhere some code that in a simplified version boils down to the
example below. Could someone explain when one would define a pointer as
that in main() below, and why? Pointers to documents that explain this
will do. Thanks!
class MyClass
{
public:
int x;
};
int main()
{
int MyClass::*px = &MyClass::x;
return 0;
}
Usually there's no good reason to use pointers to members.
Any pointer to member can be represented instead as a pointer to a
function, like
struct MyClass{ int x; };
int& xMember( MyClass& o ) { return o.x; }
int main()
{
int (*pfx)( MyClass& ) = &xMember;
}
Well, at least I think the "any" holds. Pointer to members are so
rarely used that I can't think of an example where the "any" doesn't
hold. Although such an example may exist.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?