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 contravariance and template non-type argum

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Joaquín M López Muñoz
Guest





PostPosted: Tue Jan 10, 2006 8:50 am    Post subject: Pointer to member contravariance and template non-type argum Reply with quote



The following piece of code is legal C++:

struct A
{
int x;
};

struct B:A{};

int main()
{
int B::* p=&B:Mad;
}

which is reasonable enough, as A:Mad is part of B public interface via
inheritance. Perhaps a little metaphorically, we can regard this
aliasing of a pointer to member of base as a pointer to
member of derived like a sort of contravariance rule.
But in the context of template non-type arguments, the rule does not
apply:

struct A
{
int x;
};

struct B:A{};

template<int B::*Ptr>
struct foo{};

int main()
{
// error: argument of type "int A::*" is incompatible with
// template parameter of type "int B::*"
foo<&B:Mad> f;
}

I'm sure there's some place in the standard implicitly or explicitly
banning the conversion in this particular context (though I couldn't
find it). My questions are:

* Is there any sensible reason for this banning that escapes me?
Why here (template args) and not anywhere else?
* If not, would it be a good idea to file a DR?

Thanks in advance,

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards 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.