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 / sv

1) Compiler will throw the error as C++ doesnt support +
operator for string. Another point is T c = Add
("SAM","SUNG"), where the function call assign to a
TEMPLATE object type, it syntactical error.

2)We need to write a seperate add function as given below

char* Add( const char *s1, const char*s2);

This will solve the problem

Is This Answer Correct ?    3 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what are the characteristics of Class Members in C++?

807


What is static in c++?

800


What are disadvantages of pointers?

797


What is the best book for c++ beginners?

775


What are stacks?

814


When is the destructor called?

778


If you want to share several functions or variables in several files maitaining the consistency how would you share it?

755


Who was the creator of c++?

769


What is iostream in c++ used for?

730


What is enum class in c++?

933


How can a called function determine the number of arguments that have been passed to it?

881


What is one dimensional array in c++?

817


What are the uses of pointers?

780


what Is DCS ? what i will get benefit when i did?

2038


What is a tuple c++?

741