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 full form of dos?
Which programming language is best?
What is isdigit c++?
What is a virtual destructor? Explain the use of it?
Discuss the effects occur, after an exception thrown by a member function is unspecified by an exception specification?
What does the linker do?
Why #include is used?
What is a class template in c++?
How are the features of c++ different from c?
Which compiler does turbo c++ use?
Difference between strdup and strcpy?
What is endl?
What are c++ files?
Can member data be public?
What is buffer and example?