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

Inline parameters : What does the compiler do with the parameters of inline function, that can be evaluated in runtime ?

2514


Where Malloc(), Calloc(), and realloc() does get memory?

1054


What is a down cast?

1109


What is the difference between while and do while loop? Explain with examples.

1107


Am pass the 10000 records to target in target I will take commit interval 15000 when I was stop the work flow what will happened

1559


How can you link a c++ program to c functions?

1103


If a function doesn’t return a value, how do you declare the function?

1059


Which bit wise operator is suitable for turning off a particular bit in a number?

1111


Which operations are permitted on pointers?

996


write a corrected statement in c++ so that the statement will work properly. x = y = z + 3a;

1895


Explain pass by value and pass by reference.

1055


Are there interfaces in c++?

999


Which programming language's unsatisfactory performance led to the discovery of c++?

1334


Why would you use pointers in c++?

1150


Differences between private, protected and public and give examples.

1059