0

Can I make generic function declarations at the start of my header file?

I can do template<class t> t func(t); then specialize it, but
Template Specialization VS Function Overloading
says not to do that.

Community
  • 1
  • 1
Lauer
  • 517
  • 1
  • 6
  • 11
  • 1
    Your question is unclear. What are you talking about? Declarations vs. definitions? Or specialization vs. overloading? The link you provided is about the latter. But it seems that your question might be about the former. What does all this have to do with "declarations at the start pf your header file"? – AnT stands with Russia Jul 01 '12 at 01:26

1 Answers1

1

First, you can surely declare a template function and then define it, and/or define specializations. But...

Function specializations must be full specializations, that is, you cannot partially specialize a template function. Now, while you can actually specialize the function template, providing overload may have advantages (and disadvantages), but in most cases it will be a better option.

You might want to read this: http://www.gotw.ca/publications/mill17.htm

David Rodríguez - dribeas
  • 204,818
  • 23
  • 294
  • 489