Theory Exam 1 Flashcards
Public members functions
A public member function in a Class in C++ would be a function that an external class can call because it is a public function
This would include functionality an external class could use
Private helper functions
Private helper functions are functions that are used internaly in lets say a Sphere class We will see this in the class we come up with that talks about this
Private variables
Private variables of a class in C++ are private because they contain data about a specific object
Constructors
Every class in C++ has a constructor, even if you didn’t define one
3 Types of them
Automatic Default
Custom Default
Non-Custom Default
Automatic Default Constructor
If there is no constructor defined, then C++ will define an automatic default constructor for our class.
Custom Default Constructor
This is a constructor we define ourselves, however it will have 0 parameters when called, and will initialized all the member variables of your object to default values that you programmed in this default constructor
Custom Non-Default Constructor
This would be a construtor that you would define yourself, however you actually have the constructor take in parameters so the object is filled in with initial default values
Encapsulation
Classes provide the programmer to encapsulate all the behavior to a class, sort of like creating a certain type of object that has state variable and methods, usually the methods are private to manipulate the objects data, and of course we have constructors as well.
Namespaces in C++
Creating a class that is part of a namespace (eg: Sphere is part of the cs225 namespace)
Using a class from a namespace (eg: cs225::Sphere)
using namespace cs225
Purpose and usefulness of namespaces
What is the purpose of a namespace?
What is the usefulness of a namespace?
Variables
Four properties: name, type, location (in memory), and value
Name of variable: This would just be the name of the variable Type of Variable: Type would either be primitive (int, double, float, char, etc.), or user-defined which means we are instantiating a class which would make a certain type of variable Location (in memory): Stack if not declared with the “new” keyword, othersewise if “new” is used, the variable will be on the heap Value: the value of the variable would be whatever we asign it
Primitive vs User-Defined
Primitive vs. User-defined Variables
A Primitive Variable: A primtive variable include, int, double, char, string (if header is in there), float, etc. etc.
User Defined Variable: These are variable that a user defines with a class, and can use a typedef here
Indirection in C++
What is indirection mean in C++?
Basically what we are doing when creating pointers and references is that we are able to create multiple variables that refer to the same piece of memory
int i = 7;
int &y = i; // y is an alias of i, which means if we modify y, then we will be modifying i
2 Rules of Indirection **
Multiple variables can refer to the same piece of memory
Pointers and References don’t create their own objects
Pointers and References in context of indirection
We use Pointers and References in C++, these are a level of indirection via memory to the data.
The indirection operator is a * in C++
Reference variables
What is a Reference Variable?
A reference variable is an alias to an existing variable. That means that modifying the reference variable actually modifies the variables that is being aliased. So then we may ask, what is going on internally?
Internally, a reference variable maps to the same memory as the variable being aliased.