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 / pranay
MISTAKE:
1.returning a temp object so it goes out of scope.
2.using + for c-type strings.
SOLUTION:
string s = Add("SAM","SUNG");
Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
What is the difference between the functions memmove() and memcpy()?
Which one between if-else and switch is more efficient?
What is the first name of c++?
Why c++ is better than c language?
What is c++ similar to?
What are different types of loops in c++?
What is endianness?
What is an iterator?
Do you need a main function in c++?
What return value must conversion operators have in their declaration?
What is time_t c++?
What is the advantage of an external iterator.
what are the events occur in intr activated on interrupt vector table
When do you call copy constructors?
Is java based off c++?