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
Distinguish between new and malloc and delete and free().
What are the operators in c++?
How much do c++ programmers make?
What is the most useful programming language?
What is an overflow error?
What do you mean by public protected and private in c++?
Using a smart pointer can we iterate through a container?
What are the advantage of using register variables?
Define copy constructor.
What is oop in c++?
Can you be able to identify between straight- through and cross- over cable wiring? And in what case do you use straight- through and cross-over?
What are c++ manipulators?
What is this pointer in c++?
Why do we need function?
Explain the concept of friend function in c++?