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

Can the operator == be overloaded for comparing two arrays consisting of characters by using string comparison?

1077


Evaulate: 22%5 a) 2 b) 4 c) 0

1086


How many keywords are used in c++?

1015


Write about the use of the virtual destructor?

1004


Explain method of creating object in C++ ?

1106


Mention the purpose of istream class?

1107


What are formatting flags in ios class?

1288


Write a Program for dynamically intialize a 2 dimentional array. Eg:5x20, accept strings and check for vowels and display the no.finally free the space allocated .

1143


Which should be more useful: the protected and public virtuals?

1033


What is the iunknown interface?

1123


How do you save a c++ program?

1034


What is buffering in c++?

1059


What is a vector c++?

1171


Why c++ is faster than java?

1056


What is virtual base class uses?

1348