Topic: An unknown goodie - default parameters with templates?
Author: "Andrei Alexandrescu" <andrewalex@hotmail.com>
Date: 2000/02/08 Raw View
I had the surprise to see this compiling and running successfully with MWCW
6.3:
void Foo(int i, int j = 1, int h = 2)
{
}
template <class Fun>
void Call(const Fun& fun)
{
fun(8);
}
int main()
{
Call(Foo);
}
My reasoning of the mechanics of the code goes like this: Call is
instantiated with the type 'void (&)(int, int, int)'. A reference to Foo is
passed to Call.
To the best of my knowledge, default arguments are not part of Foo's
signature. Therefore, I'd expect the call fun(8) not to work. To my
surprise, however, MWCW compiled and ran passing Foo the correct default
arguments.
This is very exciting, but I don't think it's standard. Could someone
clarify me about that?
Andrei
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]