C++

Objectives :

  • Compare with this example myTemplateFunct1.htm
    • In the current example template class "name as you like" replaced a function which was overwritten in the last example.
  • Rules explained
    • template <class Parameter> ReturnType FunctionName(Argument(s)) { }
      --------------------------------------------
      template <typename VariousType> void Show(VariousType value)
      {
    • The template keyword, the class or typename keyword, the <, and the > operators are required. The object to the key word typename or class can be your choice , and usually the programmers simply use the letter T.
    •  Next to <> enclosure, the ReturnType and Function rules are obeyed On the right side of the class keyword, type a name that follows the rules of names in C++.
       
  • generic keyword can be used in .Net platform.
  • Passing template parameter as an argument
    void Show(VariousType value)
    {
    cout<< " \n Round : "<< n1++ <<" --> Data Type Who Knows \n Data Type "
    << typeid(value).name() << " Value assigned : " << (value);
    }

Step: 1 Create a project

Step: 2 Create a source file

 

Step: 3 Edit Source code myTemplateFunct2.txt

 

Step: 4 Runtime View : d is data type id for double data type.

Step: 5 FYI only : Note template "class VariousType" handles series of overridden functions in the previous example.  myTemplateFunct1.htm