A function can return a value of type T in one of several different ways. Which of these is correct? If correct, give a short declaration of a function that returns its value by these mechanism. Comment on the const methods of function return value. Comment on when there is danger involved in returning a reference of any kind from a function. Finally, which one of these returns an l-value and which an r-value?

a) By value
b) By lazy evaluation.
c) By reference
d) By const value
e) By const reference


a) T f() x
b) Not a mechanism known in C++
c) T& f()
d) const T f()
e)const T& f()

d) and e) return a const value and reference respectively. This means you cannot call a mutator on the returned value, as f( ).mutator( ).Returning a reference to an object with a short life (a local variable is the typical error) will seem to work but fail horribly at some time later. c), returning a reference provides and l-value, that may be also be used as an r-value. Parts a) d) and e) return an r-value only, though a mutator can be called on a)’s return value. Finally a) and d) call the copy constructor to effect the return of a class object.

Computer Science & Information Technology

You might also like to view...

What is a navigational element? List three types.

What will be an ideal response?

Computer Science & Information Technology

What is established by the following style sheet?table {border: solid 6px navy;}th, td {border: solid 2px orange;}

A. table borders B. a border around the table header C. gridlines D. both a and c

Computer Science & Information Technology

Word uses ________ to identify data in a table and formats it to be used in the formula

A) a data source B) syntax C) field codes D) merge fields

Computer Science & Information Technology

The relational model describes data using a standard tabular format; all data elements are placed in three-dimensional tables called relations, which are the logical equivalent of files.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology