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
What are the two main components of c++?
What is implicit conversion/coercion in c++?
Can I run c program in turbo c++?
What is static in c++?
When to use “const” reference arguments in a function?
How many types of classes are there in c++?
What is the best way to take screenshots of a window with c++ in windows?
What is the cout in c++?
What is the difference between global variables and static varables?
Difference between strdup and strcpy?
What is #include iostream?
How do you declare a set in c++?
What is the difference between the indirection operator and the address of oper-ator?
What is a tuple c++?
What character terminates all character array strings a) b) . c) END