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 / 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


Please Help Members By Posting Answers For Below Questions

What is the exit function in c++?

1024


What is a c++ object?

1250


How do you write a function that can reverse a linked-list?

1167


What are friend classes? What are advantages of using friend classes?

1137


Is sorted c++?

1162


What is implicit pointer in c++?

1140


What does iomanip mean in c++?

1269


What is the difference between an external iterator and an internal iterator?

1141


Explain what are the sizes and ranges of the basic c++ data types?

1201


Explain virtual destructor?

1251


Which c++ compiler is best?

1202


What are literals in C++?

1077


Can comments be longer than one line?

1122


Does c++ have a hash table?

1047


an integer constant must have atleast one a) character b) digit c) decimal point

1077