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

MISTAKE:
1.returning a temp object so it goes out of scope.
2.using + for c-type strings.
SOLUTION:
string s = Add("SAM","SUNG");

Is This Answer Correct ?    1 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the 3 levels of programming languages?

1097


Can we specify variable field width in a scanf() format string? If possible how?

1350


What is ios class in c++?

1174


What are static variables?

1191


Can we make copy constructor private in c++?

1094


Explain the advantages of using friend classes.

1225


What does scope resolution operator do?

1163


What does new return if there is insufficient memory to make your new object?

1084


How the virtual functions maintain the call up?

1283


How can we read/write Structures from/to data files?

1184


What is stoi in c++?

1231


How a macro differs from a template?

1221


What is function declaration in c++ with example?

1178


What are the steps in the development cycle?

1160


Difference between overloaded functions and overridden functions

1111