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 / sg
"SAM" and "SUNG" will be considered as const char * and
there will be an compile time error. To over come this we
can call the fun as
string c = Add<string>("SAM","SUNG");
as the string class as '+' operator overloaded and it will
add the two string.
| Is This Answer Correct ? | 15 Yes | 1 No |
Post New Answer View All Answers
how to connect with oracle 9i with server in socket program in c/c++
What is a c++ map?
What are vectors used for in c++?
Explain about vectors in c ++?
What is namespace std; and what is consists of?
I was a c++ code and was asked to find out the bug in that. The bug was that he declared an object locally in a function and tried to return the pointer to that object. Since the object is local to the function, it no more exists after returning from the function. The pointer, therefore, is invalid outside.
What is the disadvantage of using a macro?
Difference between Abstraction and encapsulation in C++?
Explain the difference between static and dynamic binding of functions?
Difference between delete and free.
What size is allocated to the union variable?
What is the extension of c++?
What is a vector c++?
How do you invoke a base member function from a derived class in which you’ve overridden that function?
Define what is constructor?