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 header file for setw?
What is the function of I/O library in C++ ?
What is diamond problem in c++?
Describe the setting up of my member functions to avoid overriding by the derived class?
What is linked list in c++?
What are the basics of local (auto) objects?
Explain the pure virtual functions?
Why do we use templates?
Can you Mention some Application of C/C++?
What is a c++ class?
Where must the declaration of a friend function appear?
Mention the ways in which parameterized can be invoked.
What do you mean by public protected and private in c++?
What is a terminating character in c++?
What is the use of volatile variable?