UNIT 03 - Lecture 27 - Templates
UNIT 03 - Lecture 27 - Templates
Semester : II
SKASC 1
Topic to be Discussed
Int results:
Numbers are: 2 and 1.
Addition is: 3
Subtraction is: 1
Product is: 2
Division is: 2
Float results:
Numbers are: 2.4 and 1.2.
Addition is: 3.6
Subtraction is: 1.2
Product is: 2.88
Division is: 2
In the above program, a class template Calculator is
declared.
}
• In the above example if we not use the normal function,
when a statement call such as, max(str1,str2)
• It is executed, but it will not produce the desired result.
The above call compares memory addresses of strings
instead of their contents.
• The logic for comparing strings is different from
comparing integer and floating point data types.
• It requires the normal function having the definition but
not the function template.
• We can use both the normal function and function
template in a same program.
Overloaded Function Templates
Thank You