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 identity function in c++? How is it useful?
What is the difference between C and CPP?
How does c++ sort work?
daily Routine of father
What are the 4 types of library?
Explain terminate() function?
What is oop in c++?
Explain shallow copy?
Explain the term memory alignment?
What is the use of "new" operator?
Can we overload operator in c++?
Is c++ a good first language to learn?
Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.
What is a manipulator in c++?
Explain overriding.