C++ Ch.15

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

__ to a base class may be assigned the address of a derived class object

pointers (this can be done through assignment/initialization)

A member function of a class that is not implemented is called a(n) _______ function.

pure virtual

A function that calls itself is _____.

recursive

When a pointer to a base class is made to point to a derived class, the pointer ignores any __ the derived class performs, unless the function is __.

redefinition, virtual

Erin creates the class SpaceObject. Inside, she has a function Rotate() with, = 0 ,after the function definition. This means ____.

she will not be able to create a SpaceObject object

The compiler using type information to select how a function will be processed is an example of ____ .

static binding

When a class prototype ends with a = 0; this means ____.

the class is an abstract class and the subclasses will have to define the function

Using an abstract base class allows _____.

the programmer to create an "interface contract" where interface must be implemented by derived functions.

A __ of a base class expects to be overridden in a derived class

virtual function

When you use the virtual keyword in a virtual function ___.

virtual keyword not required in defined class

How to declare a pure virtual function?

void draw() = 0;

You are looking at the function prototype for the Rotate() function in the SpaceObject class. The function has = 0 at the end of the declaration. This means ____.

you must define Rotate() in SpaceObject

You create a class, Animal and then derive class Mammal from it. You then derive class Cat from Mammal. You want to use vectors to hold any of those objects. You define the vector zoo as type ____.

Animal

When does static binding take place? When does dynamic binding take place?

Binding - The process of matching function calls with the correct function. Static binding occurs at compile time. Dynamic binding occurs at runtime, for functions declared as virtual.term-6

A program has a class Potato, which is derived from the class Vegetable, which is derived from the class Food. Is this an example of multiple inheritance?

No. It's a chain of inheritance. Multiple inheritance refers to the situation where one derived class has multiple base classes.

What's the difference between redefining a base class function and overriding a base class function?

Overriding refers to the situation where a derived class redefines a virtual function. Overridden functions are dynamically bound, redefined functions are statically bound.

A base class may not be derived from another class.

F

A member function of a derived class may not have the same name as a member function of the base class

F

It isn't possible for a base class to have more than one constructor

F

A(n) __ of inheritance is where one class is derived from a second class, which in turn is derived from a third class.

Hierarchy

Dynamic vs static cast

Use dynamic_cast when casting from a base class type to a derived class type. It checks that the object being cast is actually of the derived class type and returns a null pointer if the object is not of the desired type (unless you're casting to a reference type -- then it throws a bad_cast exception). Use static_cast if this extra check is not necessary.

What version of member function does dynamic binding use?

Version of the member function in the actual class of the object regardless of the class of the pointer used to access the object (i.e base class). Example: Project 2 if we used virtual functions

What does virtual function do?

Virtual function allows the most specific version of a member function in an inheritance hierarchy to be selected for execution. In a sense, it makes polymorphism possible.

Polymorphism

When code with different inputs behaves differently. For instance, when Person object calls its member functions, not Cargo's.

The function A() calls B(), which has a call, A(). This is _____.

indirect recursion

What is virtual function?

A function that has no body, or definition, in the class in which it is declared.

A pointer to base class object is passed as parameter to a derived class, and I want to access treat the object as a derived class object with its associated functions. What are my two options?

1. declare function virtual 2. dynamic cast pointer

type cast

A base class pointer needs a(n) ________ to be assigned to a derived class pointer.

What is an abstract base class?

A base class that cannot itself be instantiated. A base class becomes abstract when it contains a pure virtual function: virtual void myFunction() = 0;

What are the type compatibility relationships between different classes in inheritance hierarchy?

A derived class pointer can always be assigned to a base class pointer. BUT a type ast is required to perform the opposite assignment of a base class pointer to a derived class pointer. Example: pd = static_cast<Derived *>pb;

A collection of abstract classes defining an application in skeletal form is called a(n) _______.

Application framework

What version of member function does static binding use?

Base class version (due to base class pointer) Example: Person *arr[NUM_PEOPLE] = { new TFaculty("Indiana Jones", ARCHEOLOGY, "Dr."), new Student("Thomas Cruise", COMPUTER_SCIENCE, NULL), new Faculty("James Stock", BIOLOGY), new TFaculty("Sharon Rock", BIOLOGY, "Professor"), new TFaculty("Nicole Eweman", ARCHEOLOGY, "Dr.") }; for (int k = 0; k < NUM_PEOPLE; k++) { cout << arr[k]->getName() << endl; } evoke Person class instead of any of the derived classes

In multiple inheritance, the derived class should always __ a function that has the same name in more than one base class.

Redefine

Pointers to a base class may be assigned the address of a derived class object

T

When a derived class redefines a function in a base class, which version of the function do objects that are defined of the base class and pointers to the base class call?

The base class version

Kathleen wants to create base and derrived classes with one common interface, yet implementation details for each method are specified in the derrived classes. She can do this with a(n) ____.

abstract base class

A class with at least one pure virtual member function is called a(n) ______.

abstract class

Multiple inheritance opens the opportunity for a derived class to have __ members

ambiguous

When a recursive algorithm has reached the subproblem it can directly solve, it has reached the ___ case.

base

A computer does ____ when it selects the code that should be executed when a function or class is called.

binding

Recursive functions work by ___.

breaking a complex problem down into subproblems of the same type

The function A() has a call to A() inside it. This is known as ____.

direct recursion

The computer deciding which function will be called based upon the data at hand is an example of _______.

dynamic binding

Talha wanted to prevent a virtural member function from being overridden further down the inheritance hierarchy. He can do this with ___.

final


Set pelajaran terkait

AP Psychology Personality Unit 10

View Set

LSU POLI 2051: Connect Ch. 7 Quiz

View Set

Chapter 10 - Advanced Accounting

View Set

Blood Transfusions med surg questions

View Set

Physical Development in Early Childhood

View Set

B4 Shock, Burns, Emergency/Disaster

View Set