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 are the 3 levels of programming languages?
Can we specify variable field width in a scanf() format string? If possible how?
What is ios class in c++?
What are static variables?
Can we make copy constructor private in c++?
Explain the advantages of using friend classes.
What does scope resolution operator do?
What does new return if there is insufficient memory to make your new object?
How the virtual functions maintain the call up?
How can we read/write Structures from/to data files?
What is stoi in c++?
How a macro differs from a template?
What is function declaration in c++ with example?
What are the steps in the development cycle?
Difference between overloaded functions and overridden functions