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
Write a Program for find and replace a character in a string.
What is c++ try block?
Why c++ is called oop?
Mention the storage classes in c++.
What is abstract class in c++?
Difference between declaration and definition of a variable.
What is the difference between method overloading and method overriding in c++?
What is polymorphism in c++? Explain with an example?
Reverse the Linked List. Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL
Write a Program for read a line from file from location N1 to N2 using command line arguments. Eg:exe 10 20 a.c
What are the advantages of c++ over c?
What is time h in c++?
Why do we use double in c++?
How would you use qsort() function to sort an array of structures?
Mention the ways in which parameterized can be invoked. Give an example of each.