Jump to content
  • Advertisement

Archived

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

Shannon Barber

function template default arguements

This topic is 6004 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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"?

Share this post


Link to post
Share on other sites
Advertisement
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
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!