Classes Flashcards

1
Q

Header

A

Text file defining class and implementation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Client code needs to know what about a class?

A

Member functions
Arguments for member functions
Return type of member functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Interfaces

A

Define how things interact with eachother

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What consists of a class’s interface?

A

Public member functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you separate a class’s interface from it’s implementation?

A

Class definition in header and member functions defined in source code file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Function prototypes

A

Describe class’s public interface without revealing implementation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why does class header specify class’s private data members?

A

Compiler must know how much data to reserve for each object of the class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Class header

A

Provides compiler with info to ensure class’s member functions are called correctly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an include guard?

A

ifndef, #define, #endif

Prevents header from being included multiple times

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Scope resolution operator

A

::

Tells compiler that the member function is within that class’s scope/definition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why include class header in source code file?

A

Ensures member function matches prototype and member functions know class data members and functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What exception can a function throw?

A

invalid_argument

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a throw statement?

A

Creates and throws an object of the type specified

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What happens after exception object is created?

A

throw statement immediately terminates the function and the exception is returned to the calling function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are objects of ostringstream?

A

Same functionality as cout but writes their output to string objects in memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

ostringstream’s str member function does what?

A

Returns the string created

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Stream manipulator setfill

A

Specifies fill character when integer is output in field wider than number of digits in value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Sticky setting

A

Applies to all subsequent values displayed, ex: setfill

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a member function defined in a class’s body?

A

Implicitly declared inline

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Defined classes can be used as types in declarations of…

A

Objects, references, and pointers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Member functions are stored __________ from the objects of the class

A

Separately

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What belongs to a class’s scope?

A

Data members and member functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Nonmember functions are defined at what scope?

A

Global namespace

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Within class’s scope, class members are accessible to….

A

Member non-static functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Outside of class scope, class members are referenced through….

A

An object name, a reference to an object, or a pointer to an object

26
Q

What has block-scope?

A

Variables declared in a member function

27
Q

Dot member selection operator (.)

A

Accesses the object’s, or reference to an object’s, public members

28
Q

Arrow member selection operator (->)

A

Used with pointer to access object’s public members

29
Q

Access functions

A

Read or display data
Also test truth/falsity (called predicate functions)

30
Q

Utility functions

A

Private member function that enables use of public member functions.
Not intended for use by clients

31
Q

How do you overload?

A

Provide prototypes and constructors for each overloaded version

32
Q

How can a constructor call other constructors in the same class and what is it called?

A

Use a member initializer with the name of the class

Called a delegating constructor

33
Q

Destructor

A

Called implicitly when an object is destroyed

Uses ~

34
Q

Destructor’s termination housekeeping

A

Before system can reclaim an object’s memory, it’s reused to hold new objects

35
Q

How many destructors does each class have?

A

1, if not explicitly, compiler creates empty destructor

36
Q

What order are destructor calls made?

A

Reverse of constructor calls

Global and local static destructors are called after all non-static local objects are destroyed

37
Q

What is function exit?

A

Terminates program immediately after fatal unrecoverable error occurs

Does not execute destructors

38
Q

What is function abort?

A

Terminates program immediately
Does not allow any programmer-defined cleanup
Indicates abnormal termination

39
Q

What are references?

A

Alias for name of object
Acceptable lvalue and can receive a value

40
Q

When can a reference not be used as a modifiable lvalue?

A

If the function returns a reference to const data

41
Q

What is memberwise assignment?

A

= used to assign an object to another object of the same type

42
Q

Objects can be passed by value or returned by value from functions. How?

A

Copy constructor creates new object and copies original values in

43
Q

const keyword

A

Object is not modifiable

44
Q

non-const member calls on const member objects

A

Compiler does not allow

45
Q

const member function attempt to modify object

A

Compilation error

46
Q

Where is member function declared const?

A

Prototype and definition

47
Q

const objects must be ________.

A

Initialized

48
Q

What cannot be declared const?

A

Constructors and destructors

49
Q

What is composition?

A

Class can have objects of other classes as members

50
Q

When are member objects constructed in enclosing class objects?

A

Before

51
Q

Friend functions

A

Can access all the class’s members.
Defined outside class’s scope.

52
Q

Where is friend declaration allowed?

A

Anywhere in the class

53
Q

Is friend relationship symmetric or transitive?

A

Neither

54
Q

this pointer

A

Object can access its own address
Not part of object itself

55
Q

this pointer is passed as an implicit argument to each ______________

A

Non-static member function

56
Q

This pointer can be called explicitly to reference

A

Data members and member functions

57
Q

Cascaded-member-function calls

A

When multiple functions are invoked in the same statement. Enabled by this pointer.

58
Q

Static data members

A

Class-scope
Can be public, private, or protected

59
Q

How to access public static class member when no object exists?

A

Prefix classname with name of data member and scope resolution operator

60
Q

Static can be applied to definition outside of class definition? T or F

A

True

61
Q

When should a member function be declared static?

A

If it does not access non-static members