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
By using c++ with an example describe linked list?
What is the use of class in c++?
Can you help me with this one? Make a program that when a user inputed a Product Name, it will display its price, and when the user inputed the quantity of the inputed product, it will show its total price. The output must be like this: Product Name: Price: Quantity: Total Price: ..this is the list of products to be inputed: Cellphone - 1500 Washing Machine - 5200 Television - 6000 Refrigirator - 8000 Oven - 2000 Computer - 11000 thanks..:D
How are virtual functions implemented in c++?
How do you remove an element from a set in c++?
What is #include iostream h in c++?
Is multimap sorted c++?
What is abstraction c++?
What is a static element?
What are the classes in c++?
When the constructor of a base class calls a virtual function, why doesn't the override function of the derived class gets called?
Inline parameters : What does the compiler do with the parameters of inline function, that can be evaluated in runtime ?
what Is DCS ? what i will get benefit when i did?
What is an iterator?
What is an object in c++?