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 is the best c++ compiler for windows 10?

582


What is the difference between #import and #include?

555


What is c++ best used for?

569


Explain rtti.

594


What is the basic structure of c++ program?

569






What is a .lib file in c++?

572


Which programming language is best?

551


What is the difference between interpreters and compilers?

628


What is the difference between set and map in c++?

608


What is c++ hash?

622


Explain queue. How it can be implemented?

675


How would you use qsort() function to sort an array of structures?

724


What are the characteristics of friend functions?

567


What is buffer and example?

525


Why do we use string in c++?

511