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 / mms zubeir
There are two things to be considered here.
First, T will be an unknown type in the place where we call
which gives a compilation error.
Second, if we call like this:
std::string c = Add("SAM", "SUNG"); or,
char* c = Add("SAM", "SUNG");
the compiler will convey an error since the arguments to
Add are interpretted as char pointers. The error may be
something like, "cannot add two pointers....".
| Is This Answer Correct ? | 4 Yes | 5 No |
Post New Answer View All Answers
What is flag in computer?
What is the type of 'this' pointer? When does it get created?
Explain terminate() and unexpected() function?
What do you mean by vtable and vptr in c++?
what is oops and list its features in c++?
How can you link a c program with a c function?
How const int *ourpointer differs from int const *ourpointer?
What is c++ mutable?
Write a program to encrypt the data in a way that inputs a four digit number and replace each digit by (the sum of that digit plus 7) modulus 10. Then sweep the first digit with the third, second digit with the fourth and print the encrypted number.
What are the advantages of using a pointer? Define the operators that can be used with a pointer.
Which is the best c++ compiler for beginners?
What are signs of manipulation?
What do c++ programmers do?
What do you mean by friend class & friend function in c++?
What is Destructor in C++?