| View previous topic :: View next topic |
| Author |
Message |
Peter Koch Larsen Guest
|
Posted: Sat Nov 27, 2004 2:11 am Post subject: Pointer-to-member confusion |
|
|
I've had a problem resulting most probably from me not understanding the
standard. The problem can be demonstrated with the following code:
#include <iostream>
struct base { int bi;};
struct derived: base { int di; };
void test(int base::* ) { std::cout << "basen"; }
void test(int derived::* ) { std::cout << "derivedn"; }
int main()
{
int base::* pbi = &base::bi;
int derived::* pdi = &derived::di;
pdi = &derived::bi;
pbi = &derived::bi; // 1!
test(&base::bi);
test(&derived::bi);
test(&derived::di);
}
What surprises me is that the statement at // 1! is legal. derived::bi seems
to be of type int base::*. This is confirmed with the output that prints
base
base
derived
I expected an expression of &class::member to be of type member class::*,
but apparently this is not the case. Why is this so? (This was tested on VC
8.0 Beta but Comeau online gave similar results).
Kind regards
Peter Koch Larsen
PS: The real surprise came in a templated function - something like:
template*pit = 7; }
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Thomas Mang Guest
|
Posted: Sat Nov 27, 2004 12:31 pm Post subject: Re: Pointer-to-member confusion |
|
|
"Peter Koch Larsen" <pklspam (AT) mailme (DOT) dk> schrieb im Newsbeitrag
news:L2qpd.69989$Vf.3435527 (AT) news000 (DOT) worldonline.dk...
| Quote: | I've had a problem resulting most probably from me not understanding the
standard. The problem can be demonstrated with the following code:
|
It's described in 5.3.1/2.
There's even an example almost 100% identical to yours.
Thomas
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|