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


Please Help Members By Posting Answers For Below Questions

What do you mean by a template?

625


What does override mean in c++?

592


How do you declare A pointer to a function which receives nothing and returns nothing

725


What are the benefits of operator overloading?

682


What is std :: endl?

596






What is c++ in english?

579


Why is "using namespace std;" considered bad practice?

653


What is the identity function in c++? How is it useful?

553


What is function overloading c++?

572


What is object oriented programming (oop)?

625


How can we check whether the contents of two structure variables are same or not?

591


What is type of 'this' pointer?

600


How would you find out if a linked-list is a cycle or not?

555


How a modifier is similar to mutator?

648


What does new do in c++?

639