Parameter values for templates


  • Besides the template arguments preceded by the class keywords that represent a type, function templates and class templates can include other parameters that are not types whenever they are also constant values, like for example values of fundamental types.
  • As an example see this class template that serves to store arrays:
  • It is also possible to set default values for any template parameter just as it is done with function parameters.
  • Some possible template examples seen above:
  • template < class T > // The most usual: one class parameter.
  • template < class T, class U >  	//Two class parameters.
    
  • template < class T, int N > //A class and an integer.
  • template < class T=char > //With a default value.
  • template < int Tfunc (int) > // A function as parameter
  • Function Templates<< Previous
    Next >> Exception Handling

    Our aim is to provide information to the knowledge


    comments powered by Disqus


  • Footer1