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

MISTAKE:
1.returning a temp object so it goes out of scope.
2.using + for c-type strings.
SOLUTION:
string s = Add("SAM","SUNG");

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between the functions memmove() and memcpy()?

619


Which one between if-else and switch is more efficient?

597


What is the first name of c++?

555


Why c++ is better than c language?

553


What is c++ similar to?

585






What are different types of loops in c++?

644


What is endianness?

613


What is an iterator?

680


Do you need a main function in c++?

545


What return value must conversion operators have in their declaration?

602


What is time_t c++?

598


What is the advantage of an external iterator.

565


what are the events occur in intr activated on interrupt vector table

1170


When do you call copy constructors?

634


Is java based off c++?

523