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

Can a new be used in place of old mallocq? If yes, why?

1099


Are iterators pointers?

1164


Is empty stack c++?

1002


How static variables and local variablesare similar and dissimilar?

1044


Can I learn c++ as my first language?

1113


Explain what happens when a pointer is deleted twice?

1262


What operator is used to access a struct through a pointer a) >> b) -> c) *

1125


What is the disadvantage of using a macro?

1128


Define pre-condition and post-condition to a member function in c++?

1153


How much do c++ programmers make?

1120


Should a constructor be public or private?

1038


Can we make copy constructor private in c++?

1060


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

1084


Is facebook written in c++?

1001


Mention the ways in which parameterized can be invoked. Give an example of each.

1066