Chapter 10 ( Operator Overloading: Class String )

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Overloading Binary Operators

A binary operator can be overloaded as a non-static member function with one argument or as a non-member function with two arguments.

Explicit

A constructor that's declared explicit cannot be used in an implicit conversion.

Free Store ( Heap )

A region of memory assigned to each program for storing objects dynamically allocated at execution time.

new operator

Allocates storage of the proper size for an object, runs the object's constructor and returns a pointer of the correct type.

self-assignment

An object is assigned to itself.

Fundamentals of Operator Overloading

An operator is overloaded by writing a non-static member-function definition or non-member function definition in which the function name is the keyword operator followed by the symbol for the operator being overloaded. When operators are overloaded as member functions, they must be non-static, because they must be called on an object of the class and operate on that object. To use an operator on class objects, you must define an overloaded operator function, with three exceptions the assignment operator (=), the address operator (&) and the comma operator (,).

Dynamic Memory Management

Enables you to control the allocation and deallocation of memory in a program for any built-in or user-defined type.

Overloading the Function Call Operator ()

Functions can have an arbitrary number of parameters.

String-Object Literal

Indicated by placing the letter s immediately following the closing of a string literal.

>> Operator

Known as stream extraction operator and as the bitwise right-shift operator.

<< Operator

Known as stream insertion operator and as the bitwise left-shift operator.

empty

Member function which returns true if the string is empty, otherwise, it returns false.

Conversion Operator

Must be a non-static member function. Overloaded cast-operator function can be defined for converting objects of user-defined types into fundamental types or into objects of other user-defined types.

substr

Obtains a substring of a length specified by the second argument, starting at the position specified by the first argument. When the second argument is not specified, substr returns the remainder of the string on which it's called.

Conversion Constructors

Single argument constructors that turn objects of other types into objects of a particular class.

boolalpha

The stream manipulator sets an output stream to display condition values as the strings "false" and "true", rather than 0 and 1.

Delete operator

To destroy a dynamically allocated object and free its space. Ex) delete[]

Fundamentals of Operator Overloading (2)

You cannot change the precedence and associativity of an operator by overloading. You cannot change the "arity" of an operator ( the number of operands an operator takes) You cannot create new operators, only existing operators can be overloaded. You cannot change the meaning of how an operator works on objects of fundamental types. Overloading an assignment operator and an addition operator for a class does not imply that += is also overloaded. You must explicitly overload operator += for that class.

Overloading the Binary Stream Insertion and Stream Extration Operators

setw restricts the number of characters read to the number of characters specified by its argument.


संबंधित स्टडी सेट्स

"Θα σου κάνω μερικές ερωτήσεις και θα πρέπει να μου απαντήσεις με σωστή σύνταξη. Θα σου έχω πίσω από την ερώτηση πως θα πρέπει να είναι η απάντησή σου αν δυσκολευτείς."

View Set

Amendments to the U.S. Constitution

View Set

Public speaking week 15 study guide

View Set

Digital Photography Unit 2: Capturing Digital Photographs

View Set

Fundamentals of Financial Planning

View Set

SAT Practice Math Questions (Open-Ended)

View Set

Chapter 16: Music After Beethoven: Romanticism

View Set

Substance-Related and Addictive Disorders

View Set