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 is the difference between the compiler and the preprocessor?
What is the keyword auto for?
Is c++ pass by reference or value?
Distinguish between new and malloc and delete and free().
What is the use of data hiding?
What is the difference between a reference and a pointer?
Explain the use of this pointer?
What does the following code do: int c=0; cout< a) Undefined *Updated* b) 01 c) 00
Can I learn c++ without c?
What are the 3 levels of programming languages?
How does work in c++?
Is c better than c++?
Why is polymorphism useful?
What do you mean by a template?
What is ctime c++?