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 / tathagata chakraborty

None of the other answers are coming to the point of this
question.They r all wrong.

right answer is the code will crash while returning frm Add
(). bcause the function is returning a local variable of
type T i.e. a+b as a refference. u cannont return a local
variable as refference bcause that will go out of scope as
soon as the function returns.

Is This Answer Correct ?    11 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a pointer how and when is it used?

565


Is empty stack c++?

513


What are manipulators used for?

599


What is the use of data hiding?

585


Why null pointer is used?

574






What is this pointer in c++?

716


What is c++ & why it is used?

579


What does override mean in c++?

571


What is difference between class and structure in c++?

609


You run a shell on unix system. How would you tell which shell are you running?

645


Explain the difference between struct and class in terms of access modifier.

689


What is scope in c++ with example?

619


Can you declare an array without a size in c++?

563


Difference between Abstraction and encapsulation in C++?

568


Is c++ harder than java?

556