Classes Flashcards
Header
Text file defining class and implementation
Client code needs to know what about a class?
Member functions
Arguments for member functions
Return type of member functions
Interfaces
Define how things interact with eachother
What consists of a class’s interface?
Public member functions
How do you separate a class’s interface from it’s implementation?
Class definition in header and member functions defined in source code file
Function prototypes
Describe class’s public interface without revealing implementation
Why does class header specify class’s private data members?
Compiler must know how much data to reserve for each object of the class
Class header
Provides compiler with info to ensure class’s member functions are called correctly
What is an include guard?
ifndef, #define, #endif
Prevents header from being included multiple times
Scope resolution operator
::
Tells compiler that the member function is within that class’s scope/definition
Why include class header in source code file?
Ensures member function matches prototype and member functions know class data members and functions
What exception can a function throw?
invalid_argument
What is a throw statement?
Creates and throws an object of the type specified
What happens after exception object is created?
throw statement immediately terminates the function and the exception is returned to the calling function
What are objects of ostringstream?
Same functionality as cout but writes their output to string objects in memory
ostringstream’s str member function does what?
Returns the string created
Stream manipulator setfill
Specifies fill character when integer is output in field wider than number of digits in value
Sticky setting
Applies to all subsequent values displayed, ex: setfill
What is a member function defined in a class’s body?
Implicitly declared inline
Defined classes can be used as types in declarations of…
Objects, references, and pointers
Member functions are stored __________ from the objects of the class
Separately
What belongs to a class’s scope?
Data members and member functions
Nonmember functions are defined at what scope?
Global namespace
Within class’s scope, class members are accessible to….
Member non-static functions