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

How do c++ struct differs from the c++ class?

832


What is the most common mistake on c++ and oo projects?

718


Describe private, protected and public?

808


What is object file? How can you access object file?

830


How do you declare a set in c++?

725


Is c++ a float?

794


What language is a dll written in?

723


what does the following statement mean? int (*a)[4]

820


Is swift a good first language?

782


How do you declare A pointer to function which receives an int pointer and returns a float pointer

894


What is fixed in c++?

763


Evaluate !(1&&1||1&&0) a) Error b) False c) True

943


If dog is a friend of boy, is boy a friend of dog?

767


What do the header files usually contains?

805


Write my own zero-argument manipulator that should work same as hex?

793