Consider a c++ template funtion
template<class T>
T& Add(T a, T b){return a+b ;}
if this function is called as
T c = Add("SAM", "SUNG");
what will happen? What is the problem in the template
declaration/ How to solve the problem.
Answer Posted / sg
"SAM" and "SUNG" will be considered as const char * and
there will be an compile time error. To over come this we
can call the fun as
string c = Add<string>("SAM","SUNG");
as the string class as '+' operator overloaded and it will
add the two string.
Is This Answer Correct ? | 15 Yes | 1 No |
Post New Answer View All Answers
What do you mean by a template?
What does override mean in c++?
How do you declare A pointer to a function which receives nothing and returns nothing
What are the benefits of operator overloading?
What is std :: endl?
What is c++ in english?
Why is "using namespace std;" considered bad practice?
What is the identity function in c++? How is it useful?
What is function overloading c++?
What is object oriented programming (oop)?
How can we check whether the contents of two structure variables are same or not?
What is type of 'this' pointer?
How would you find out if a linked-list is a cycle or not?
How a modifier is similar to mutator?
What does new do in c++?