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
Write a program to concatenate two strings.
Are strings immutable in c++?
Arrange Doubly linked list in the ascending order of its integral value and replace integer 5 with 7?
What is the difference between containment and delegation?
Can you declare an array without a size in c++?
How do you find out if a linked-list has an end? (I.e. The list is not a cycle)
Is c++ used anymore?
What is doubly linked list in c++?
Am studying basic c++ programming, have been given the following assignment. Design a linear program to calculate the maximum stress a material can withstand given a force and a diameter of a circle. To find the required area pi should be defined. Have most of the program sorted out but am at a loss as to how to show the calculations required. Can anyone help?
What is an orthogonal base class in c++?
What is a string example?
What is pointer -to-members in C++? Give their syntax?
Explain stack unwinding.
Explain the differences between list x; & list x();.
What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator?