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
How do c++ struct differs from the c++ class?
What is the most common mistake on c++ and oo projects?
Describe private, protected and public?
What is object file? How can you access object file?
How do you declare a set in c++?
Is c++ a float?
What language is a dll written in?
what does the following statement mean? int (*a)[4]
Is swift a good first language?
How do you declare A pointer to function which receives an int pointer and returns a float pointer
What is fixed in c++?
Evaluate !(1&&1||1&&0) a) Error b) False c) True
If dog is a friend of boy, is boy a friend of dog?
What do the header files usually contains?
Write my own zero-argument manipulator that should work same as hex?