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
Explain pass by value and pass by reference.
What is conditions when using boolean operators?
What do you mean by stack unwinding in c++?
What is std :: endl?
Suppose that data is an array of 1000 integers. Write a single function call that will sort the 100 elements data [222] through data [321].
Can a constructor return a value?
What is the difference between the indirection operator and the address of oper-ator?
Differentiate between C and C++.
If a header file is included twice by mistake in the program, will it give any error?
When must you use a pointer rather than a reference?
What is the return value of the insertion operator?
How do you define a class in c++?
What is the size of a vector?
What is flush programming?
What is setiosflags c++?