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 do you mean by early binding?
What is the best ide for c++?
In which header file does one find isalpha() a) conio.h b) stdio.h c) ctype.h
Which programming language's unsatisfactory performance led to the discovery of c++?
Can I learn c++ without c?
Which compiler does turbo c++ use?
Why was c++ created?
What is the precedence when there is a global variable and a local variable in the program with the same name?
What is size_type?
Why is c++ not purely object oriented?
Will this c++ program execute or not?
What is iterator c++?
Why namespace is used in c++?
What are arrays c++?
What is data hiding c++?