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


Please Help Members By Posting Answers For Below Questions

What is the full form of dos?

570


Which programming language is best?

558


What is isdigit c++?

579


What is a virtual destructor? Explain the use of it?

553


Discuss the effects occur, after an exception thrown by a member function is unspecified by an exception specification?

644






What does the linker do?

597


Why #include is used?

619


What is a class template in c++?

527


How are the features of c++ different from c?

596


Which compiler does turbo c++ use?

610


Difference between strdup and strcpy?

653


What is endl?

639


What are c++ files?

583


Can member data be public?

599


What is buffer and example?

527