C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Pointer-to-member confusion

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Peter Koch Larsen
Guest





PostPosted: Sat Nov 27, 2004 2:11 am    Post subject: Pointer-to-member confusion Reply with quote



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





PostPosted: Sat Nov 27, 2004 12:31 pm    Post subject: Re: Pointer-to-member confusion Reply with quote




"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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.