Archived

This topic is now archived and is closed to further replies.

Shannon Barber

function template default arguements

Recommended Posts

Void    126
Wow, it''s an undocumented error code in my MSDN!

No you can. This compiles fine on VC++ 6

  
template <typename T>
void F( T t1, T t = 0 )
{
}
int main()
{
F( 3 );
return 0;
}

Share this post


Link to post
Share on other sites
Fruny    1658
If you want default template arguments, you can declare a second template with fewer arguments, that then calls the original.

template< class T, int i > f() { do stuff; }
template< class T > f() { f(); }

Remember that function templates do not work like class templates, in that the compiler tries to ''guess'' exactly which template to create each time a function is called, based on the arguments & stuff. The compiler could find a conflict between the user-defined default and the arguments.

Share this post


Link to post
Share on other sites