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

None of the other answers are coming to the point of this
question.They r all wrong.

right answer is the code will crash while returning frm Add
(). bcause the function is returning a local variable of
type T i.e. a+b as a refference. u cannont return a local
variable as refference bcause that will go out of scope as
soon as the function returns.

Is This Answer Correct ?    11 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I improve my c++ skills?

1075


Define basic type of variable used for a different condition in C++?

1065


How does list r; differs from list r();?

1099


Difference between overloading vs. Overriding

1040


What is function overriding in c++?

1027


What is cin clear () in c++?

1145


How do you clear a map in c++?

1076


How would you find out if a linked-list is a cycle or not?

967


What do c++ programmers do?

1019


How to declare a function pointer?

962


What is decltype c++?

954


What is the basic structure of a c++ program?

1093


Carry out conversion of one object of user-defined type to another?

999


Explain what are single and multiple inheritances in c++?

987


Is c++ the best programming language?

975