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
Is main a class in c++?
Is C++ case sensitive a) False b) Depends on implementation c) True
What is object file? How can you access object file?
What's the best free c++ profiler for windows?
Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?
How can we access protected and private members of a class?
How do you flush a buffer in c++?
What is the use of dot in c++?
What is the last index number in an array of 100 characters a) 100 b) 99 c) 101
What is the copy-and-swap idiom?
What do you mean by stack unwinding in c++?
Is c++ double?
What would happen on forgetting [], while deallocating an array through new?
Explain the isa and hasa class relationships. How would you implement each?
What are the uses of pointers?