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 are the differences between the function prototype and the function defi-nition?
How we can differentiate between a pre and post increment operators during overloading?
What is a .lib file in c++?
What are libraries in c++?
What is lazy initialization in c++?
Why is c++ awesome?
What is the difference between the functions memmove() and memcpy()?
Explain method of creating object in C++ ?
how to connect with oracle 9i with server in socket program in c/c++
How would you use the functions randomize() and random()?
How do you clear a map in c++?
How is c++ different from java?
Why is swift so fast?
What information can an exception contain?
Is there a c++ certification?