Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

How would you use the functions randomize() and random()?

1135


What is the difference between C and CPP?

1212


What are the various storage classes in C++?

1184


What is static function? Explain with an example

1130


What is c++ code?

1176


What is the type of 'this' pointer? When does it get created?

1001


How we can differentiate between a pre and post increment operators during overloading?

1156


What is the first name of c++?

1105


What is vector processing?

1206


How can you quickly find the number of elements stored in a static array?

1137


What are activex and ole?

1113


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

2628


What new()is different from malloc()?

1162


How many characters are recognized by ANSI C++?

1465


If you hear the cpu fan is running and the monitor power is still on, but you did not see anything show up in the monitor screen. What would you do to find out what is going wrong?

1199