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 is the best c++ compiler for windows 10?
What is the difference between #import and #include?
What is c++ best used for?
Explain rtti.
What is the basic structure of c++ program?
What is a .lib file in c++?
Which programming language is best?
What is the difference between interpreters and compilers?
What is the difference between set and map in c++?
What is c++ hash?
Explain queue. How it can be implemented?
How would you use qsort() function to sort an array of structures?
What are the characteristics of friend functions?
What is buffer and example?
Why do we use string in c++?