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 are the two main components of c++?

591


What is implicit conversion/coercion in c++?

657


Can I run c program in turbo c++?

584


What is static in c++?

594


When to use “const” reference arguments in a function?

581






How many types of classes are there in c++?

596


What is the best way to take screenshots of a window with c++ in windows?

569


What is the cout in c++?

554


What is the difference between global variables and static varables?

573


Difference between strdup and strcpy?

650


What is #include iostream?

741


How do you declare a set in c++?

536


What is the difference between the indirection operator and the address of oper-ator?

606


What is a tuple c++?

547


What character terminates all character array strings a) b) . c) END

672