0

What is proper syntax for a function that takes a template parameter as an argument i.e.

 void myFunction (const Foo::Bar<T>& x)

Is it

 template<typename T>
 void myFunction (const typename Foo::Bar<T>& x)

Also, should I use

template<typename T>

Or

template<class T>

Thanks.

Brian Bi
  • 111,498
  • 10
  • 176
  • 312
Sigmund Fraud
  • 173
  • 1
  • 7
  • See http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords?rq=1 and http://stackoverflow.com/questions/213121/use-class-or-typename-for-template-parameters?rq=1 (note both of these are in the related links on the right) – chris Jul 23 '14 at 18:18

1 Answers1

0

You got it.

template<typename T>
void myFunction (const typename Foo::Bar<T>& x)

Is correct. It doesn't matter whether you use class or typename. typename is preferred, class is in there for historical reasons. They are completely identical, though. Check out this question for some explanation.

Community
  • 1
  • 1
jaredready
  • 2,398
  • 4
  • 23
  • 50