Skip to main content
gamedev.net
🔒 Locked

function template default arguements

Started by Shannon Barber 1 reply 350+ views
Original Post
Shannon Barber
Shannon Barber
function template parameters aren''t allowed to have defaults!??!
quote:
warning C4519: default template arguments are only allowed on a class template; ignored
Is this the spec or an MSVC "quirk"?
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Void
Void
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;
}

Fruny
Fruny
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.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.