Ch. 10 Operator Overloading; Class string (Together with Ch. 9 Possibly)

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Assume that the function call operator() is overloaded for data type String in the usual sense of selecting a substring from a larger string. For a String object string1 with the character string "ABCDEFGHI", what string does string1( 4 , 2 ) return?

"EF".

Which of the following operators can be overloaded as a global function?

==.

Which of the following is false?

A string can be defined to store any data type.

Conversion constructors cannot:

Be used implicitly in series to match the needs of an overloaded operator.

For operators overloaded as non-static member functions:

Binary operators can have one argument, and unary operators cannot have any.

To prevent class objects from being copied:

Both (a) and (b).

Which of the following is false?

C++ ensures that you cannot "walk off" either end of an array.

Conversion constructors:

Can convert between user-defined types.

The delete [] operator:

Can delete an entire array of objects declared using new.

There exists a data type Date with member function Increment that increments the current Date object by one. The ++ operator is being overloaded to postincrement an object of type Date. Select the correct implementation:

Date Date::operator++( int ) { Date temp = *this; Increment(); return temp; }.

A copy constructor:

Is a constructor that initializes a newly declared object to the value of an existing object of the same class.

An overloaded + operator takes a class object and a double as operands. For it to be commutative (i.e., a + b and b + a both work):

It must be overloaded twice; the operator+ function that takes the object as the left operand must be a member function, and the other operator+ function must be a global function.

Which of the following is false?

It's not possible to pass a list initializer to a constructor.

To use an operator on user-defined class objects, operator overloading:

Must always be used, with three exceptions.

An explicit constructor:

Must take exactly one argument.

A copy constructor must receive its argument by reference because:

Otherwise infinite recursion occurs.

Which of the following is not a disadvantage of default memberwise copy with objects containing pointers?

Requiring the explicit overloading of the assignment operator.

The prototypes of overloaded cast operator functions do not:

Specify a return type.

The array subscript operator [], when overloaded, cannot:

Take multiple values inside (e.g., [4 8]).

To implicitly overload the += operator:

The += operator cannot be overloaded implicitly.

Which statement about operator overloading is false?

The += operator cannot be overloaded implicitly.

Which situation would require the operator to be overloaded as a global function? Which situation would require the operator to be overloaded as a non-member function?

The left operand is an int.

Because the postfix increment operator returns objects by value and the prefix increment operator returns objects by reference:

The postfix increment operator typically returns a temporary object that contains the original value of the object before the increment occurred.

Which of the following lines would be the prototype for an overloaded cast operator function that converts an object of user-defined type Time into a double?

Time::operator double() const;.

The conventional way to distinguish between the overloaded preincrement and postincrement operators (++) is:

To make the argument list of postincrement include an int.

Which of the following statements about a unique_ptr object is false?

You must explicitly delete the memory that's managed by a unique_ptr before the object goes out of scope.

The correct function name for overloading the addition (+) operator is:

operator+.

Suppose you have a programmer-defined data type Data and want to overload the << operator to output your data type to the screen in the form cout << dataToPrint; and allow cascaded function calls. The first line of the function definition would be:

ostream &operator<<( ostream &output, const Data &dataToPrint ).

Which of the following is not an operator overloaded by the C++ language?

pow.

Suppose the unary ! operator is an overloaded member function of class String. For a String object s, which function call is generated by the compiler when it finds the expression !s?

s.operator!().

y and z are user-defined objects and the += operator is an overloaded member function. The operator is overloaded such that y += z adds z and y, then stores the result in y. Which of the following expressions is always equivalent to y += z?

y.operator+=( z ).


Ensembles d'études connexes

Community Quiz 3 Practice Questions

View Set

Maternal Newborn Exam 2 Questions BB

View Set

frankenstien quiz (chapters 1-17)

View Set

Microeconomics 2 Final verbal questions (2021)

View Set

World Between the Wars: Assesements

View Set

CIS 192 70-412 Disaster Recovery Testout Questions

View Set

A+ Chapter 7: Wireless and SOHO Networks

View Set

Finance- Ch. 2 Financial Markets

View Set