Re: Rationale for 14.3.2/5 [temp.arg.nontype], pointer to object non-type template-parameters
On 7 Mrz., 18:37, AlbertoBarb...@libero.it (Alberto Ganesh Barbati)
wrote:
Daniel Kr?gler ha scritto:
So, if VS2005 compiles this successfully (modulo function definition),
it behaves non-conforming in this regard (Even VS2005-SP1
does accept this program).
Interesting. How does VS2005 compile this, then?
struct base{};
struct derived:base{};
template<base*> void foo() {}
template<derived*> void foo() {} // overload!
derived d;
int main()
{
foo<&d>(); // should unambigously select foo<derived*>
}
For the OP: this example might show the rationale that you were asking.
If you allow derived-to-base conversion, foo<derived*> can never be
called, unless complex "best-match" rules are further introduced to
disambiguate this scenario. I've never seen this case used in practice,
so I guess the committee decided that writing down those rules just
wasn't worth the effort.
Good point. VS2005-SP1 behaves exactly as you predict:
"error C2668: 'foo' : ambiguous call to overloaded function
main.cpp(5): could be 'void foo<& d>(void)'
main.cpp(4): or 'void foo<& d>(void)'
while trying to match the argument list '(void)'"
Greetings from Bremen,
Daniel
---
[ 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.comeaucomputing.com/csc/faq.html ]