Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 7th, 2012  |  syntax: None  |  size: 0.57 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Why does inlining template specializations help and should I do it?
  2. template <typename foo>
  3. void f(foo p)
  4. {
  5.   std::cout << "f one" << std::endl;
  6. }
  7.  
  8. template <>
  9. void f<int>(int p)
  10. {
  11.   std::cout << "f two" << std::endl;
  12. }
  13.        
  14. templateordering.obj : error LNK2005: "void __cdecl f<int>(int)" (??$f@H@@YAXH@Z) already defined in othertu.obj
  15.        
  16. template <>
  17. inline void f<int>(int p)
  18. {
  19.   std::cout << "f two" << std::endl;
  20. }
  21.        
  22. template<> void f<int>(int p);
  23.        
  24. template <>
  25. void f<int>(int p);
  26.        
  27. template <>
  28. static void f<int>(int p)
  29. {
  30.   std::cout << "f two" << std::endl;
  31. }