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
What is the exit function in c++?
What is a c++ object?
How do you write a function that can reverse a linked-list?
What are friend classes? What are advantages of using friend classes?
Is sorted c++?
What is implicit pointer in c++?
What does iomanip mean in c++?
What is the difference between an external iterator and an internal iterator?
Explain what are the sizes and ranges of the basic c++ data types?
Explain virtual destructor?
Which c++ compiler is best?
What are literals in C++?
Can comments be longer than one line?
Does c++ have a hash table?
an integer constant must have atleast one a) character b) digit c) decimal point