Introduction to Classes Flashcards
What is the focus in procedural programming?
To create functions that implement our program logic. We pass data objects to these functions, those functions perform operations on the data and potentially return a result
What is the focus in object-oriented programming?
To create program defined data types that contain properties and well defined behaviours
class invariant
a condition that must be true for the lifetime of an object for the object to remain in a valid state
invalid state
an object that has a violated class invariant. Unexpected or undefined behaviour may result from further use of that object
class
program defined compound type with data, and functions which work on that data
member functions
functions that belong to a class type
implicit object
the object that a member function is called on
non member functions
name for functions that are not member functions
what should you do if your class has no data members
use a namespace instead
const member functions
member function that guarantees it will not modify the object or call any non-const member functions (as they may modify the object)
a member function that does not (and will not ever) modify the state of the object should be made const, so that it can be called on both non-const and const objects
access level
each member of a class has an access level that determines who can access that member.
access levels are defined on a per class basis not a per object basis
access controls
access level system informally called this
public members
members of a class type that do not have any restrictions on how they can be accessed. Public members can be accessed by anyone (as long as they are in scope). This includes other members of the same class or code outside of the class
the public
code that exists outside the members of a given class type
includes:
non-member functions
members of other class types
What is the default access level for all members of a struct?
public
private members
members of a class type that can only be accessed by other members of the same class
What is the default access level for all members of a class?
private
is a class with private members an aggregate?
no and therefore it cannot use aggregate initialisation
how should you name private members?
starting with a m_ prefix. his helps distinguih them from the names of local variables, function parameters and member functions
access specifier
allows you to explicitly set the access level of our members