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
What is difference between malloc()/free() and new/delete?
What is command line arguments in C++? What are its uses? Where we have to use this?
What is the most useful programming language?
Can a program run without main?
If a round rectangle has straight edges and rounded corners, your roundrect class inherits both from rectangle and from circle, and they in turn both inherit from shape, how many shapes are created when you create a roundrect?
We all know that a const variable needs to be initialized at the time of declaration. Then how come the program given below runs properly even when we have not initialized p?
Write a program that takes a 5 digit number and calculates 2 power that number and prints it.
What is an iterator class in c++?
Which command properly allocates memory a) char *a=new char[20]; b) char a=new char[20]; c) char a=new char(20.0);
What is c++ redistributable?
How many namespaces are there in c++?
What is dev c++ used for?
What is the last index number in an array of 100 characters a) 100 b) 99 c) 101
Can I have a reference as a data member of a class? If yes, then how do I initialise it?
What can I use instead of namespace std?