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
How can I improve my c++ skills?
Define basic type of variable used for a different condition in C++?
How does list r; differs from list r();?
Difference between overloading vs. Overriding
What is function overriding in c++?
What is cin clear () in c++?
How do you clear a map in c++?
How would you find out if a linked-list is a cycle or not?
What do c++ programmers do?
How to declare a function pointer?
What is decltype c++?
What is the basic structure of a c++ program?
Carry out conversion of one object of user-defined type to another?
Explain what are single and multiple inheritances in c++?
Is c++ the best programming language?