struct A
{
int x;
};
struct B:A{};
int main()
{
int B::* p=&B::x;
}
which is reasonable enough, as A::x 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::x> 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...@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]