By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,819 Members | 1,185 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,819 IT Pros & Developers. It's quick & easy.

has anyone seen this?

P: n/a
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;
}
Mar 10 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
* 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?
Mar 10 '07 #2

P: n/a
Amadeus W.M. wrote:
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!
Google [C++ faq member pointer]

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Mar 10 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.