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 protected inheritance?
What do c++ programmers do?
Can we inherit constructor in c++?
Which is the best c++ compiler for beginners?
Is python written in c or c++?
What is a memory leak c++?
What is a c++ vector?
Is c++ a difficult language?
What is c++ and its features?
Should I learn c or c++ first?
What is diamond problem in c++?
If a base class declares a function to be virtual, and a derived class does not use the term virtual when overriding that class, is it still virtual when inherited by a third-generation class?
Why do you use the namespace feature?
Explain the difference between c & c++?
How a new operator differs from the operator new?