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
Outside of class scope, class members are referenced through....
An object name, a reference to an object, or a pointer to an object
26
What has block-scope?
Variables declared in a member function
27
Dot member selection operator (.)
Accesses the object's, or reference to an object's, public members
28
Arrow member selection operator (->)
Used with pointer to access object's public members
29
Access functions
Read or display data Also test truth/falsity (called predicate functions)
30
Utility functions
Private member function that enables use of public member functions. Not intended for use by clients
31
How do you overload?
Provide prototypes and constructors for each overloaded version
32
How can a constructor call other constructors in the same class and what is it called?
Use a member initializer with the name of the class Called a delegating constructor
33
Destructor
Called implicitly when an object is destroyed Uses ~
34
Destructor's termination housekeeping
Before system can reclaim an object's memory, it's reused to hold new objects
35
How many destructors does each class have?
1, if not explicitly, compiler creates empty destructor
36
What order are destructor calls made?
Reverse of constructor calls Global and local static destructors are called after all non-static local objects are destroyed
37
What is function exit?
Terminates program immediately after fatal unrecoverable error occurs Does not execute destructors
38
What is function abort?
Terminates program immediately Does not allow any programmer-defined cleanup Indicates abnormal termination
39
What are references?
Alias for name of object Acceptable lvalue and can receive a value
40
When can a reference not be used as a modifiable lvalue?
If the function returns a reference to const data
41
What is memberwise assignment?
= used to assign an object to another object of the same type
42
Objects can be passed by value or returned by value from functions. How?
Copy constructor creates new object and copies original values in
43
const keyword
Object is not modifiable
44
non-const member calls on const member objects
Compiler does not allow
45
const member function attempt to modify object
Compilation error
46
Where is member function declared const?
Prototype and definition
47
const objects must be ________.
Initialized
48
What cannot be declared const?
Constructors and destructors
49
What is composition?
Class can have objects of other classes as members
50
When are member objects constructed in enclosing class objects?
Before
51
Friend functions
Can access all the class's members. Defined outside class's scope.
52
Where is friend declaration allowed?
Anywhere in the class
53
Is friend relationship symmetric or transitive?
Neither
54
this pointer
Object can access its own address Not part of object itself
55
this pointer is passed as an implicit argument to each ______________
Non-static member function
56
This pointer can be called explicitly to reference
Data members and member functions
57
Cascaded-member-function calls
When multiple functions are invoked in the same statement. Enabled by this pointer.
58
Static data members
Class-scope Can be public, private, or protected
59
How to access public static class member when no object exists?
Prefix classname with name of data member and scope resolution operator
60
Static can be applied to definition outside of class definition? T or F
True
61
When should a member function be declared static?
If it does not access non-static members