Type Inference alludes to programmed allowance of the information kind of an articulation in a programming language. Before C++ 11, every information type should be unequivocally proclaimed at aggregate time, restricting the estimations of an articulation at runtime yet after the new form of C++, numerous watchwords are incorporated which permits a developer to leave the sort allowance to the compiler itself.
As all the sorts are concluded in compiler stage just, the ideal opportunity for assemblage increments marginally however it doesn't influence the run season of the program.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
template<class A, class B, class C> | |
auto Sum_num(A a,B b,C c) ->decltype(a+b+c) | |
{ | |
return (a+b+c); | |
} | |
int main() | |
{ | |
cout<<"Sum of number "<<Sum_num(1,2,3)<<" "<<endl; | |
cout<<"Sum of number "<<Sum_num(1.5,2.4,3.4)<<" "<<endl; | |
cout<<"Sum of number "<<Sum_num('a','b','c')<<" "<<endl; | |
} |
Sum of number 6 Sum of number 7.3 Sum of number 294
0 Comments
If you have any doubt and suggestion Please let me know