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);
}
|