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 / sv
1) Compiler will throw the error as C++ doesnt support +
operator for string. Another point is T c = Add
("SAM","SUNG"), where the function call assign to a
TEMPLATE object type, it syntactical error.
2)We need to write a seperate add function as given below
char* Add( const char *s1, const char*s2);
This will solve the problem
Is This Answer Correct ? | 3 Yes | 8 No |
Post New Answer View All Answers
Differentiate between declaration and definition.
What is a hash function c++?
What is pointer -to-members in C++? Give their syntax?
What is #include iostream?
What's the hardest coding language?
write asingle linked list which read from two list & the do the following 1 sort the prime & nonprime num (prime should be less tn nonprime) 2 each node has a prime num followd by nonprime 3 add a new node into its sutable plce 4 erase the most three duplicated non prime num 5 find the least duplicated prime num
What is new in c++?
What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator?
How the programmer of a class should decide whether to declare member function or a friend function?
Can a constructor return a value?
Can recursive program be written in C++?
What do you mean by inheritance in c++?
What does n mean in c++?
What function initalizes variables in a class: a) Destructor b) Constitutor c) Constructor
What are the restrictions apply to constructors and destructors?