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
Inline parameters : What does the compiler do with the parameters of inline function, that can be evaluated in runtime ?
Where Malloc(), Calloc(), and realloc() does get memory?
What is a down cast?
What is the difference between while and do while loop? Explain with examples.
Am pass the 10000 records to target in target I will take commit interval 15000 when I was stop the work flow what will happened
How can you link a c++ program to c functions?
If a function doesn’t return a value, how do you declare the function?
Which bit wise operator is suitable for turning off a particular bit in a number?
Which operations are permitted on pointers?
write a corrected statement in c++ so that the statement will work properly. x = y = z + 3a;
Explain pass by value and pass by reference.
Are there interfaces in c++?
Which programming language's unsatisfactory performance led to the discovery of c++?
Why would you use pointers in c++?
Differences between private, protected and public and give examples.