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
Can a new be used in place of old mallocq? If yes, why?
Are iterators pointers?
Is empty stack c++?
How static variables and local variablesare similar and dissimilar?
Can I learn c++ as my first language?
Explain what happens when a pointer is deleted twice?
What operator is used to access a struct through a pointer a) >> b) -> c) *
What is the disadvantage of using a macro?
Define pre-condition and post-condition to a member function in c++?
How much do c++ programmers make?
Should a constructor be public or private?
Can we make copy constructor private in c++?
Can the operator == be overloaded for comparing two arrays consisting of characters by using string comparison?
Is facebook written in c++?
Mention the ways in which parameterized can be invoked. Give an example of each.