The Chernotes #2
Your handy study guide and review sheet
CLASSES AND STRUCTS
Object oriented programming is a style you can adopt. Some languages like ____ and _____ are meant to be object oriented.
____ doesn't have classes, but it was added in C++.
Why don't we just make loose variables in our code to represent a player?
Syntax: What do we need after the closing curly brace when defining a type?
A variable made from a class type is called an ______.
Creating a new ______ of a class it is called instantiation.
Why can't we access "x" directly via the dot operator?
How is the default access level for a class different in C++ relative to Java?
Moving the Player
Cherno writes a move function. It goes pretty quick - pause it and make sure you understand this. Why pass by reference?
How do you move the function into the player class?
What is the difference?
What is the default visibility of a class?
What is the default visibility of a struct?
Are there any other differences between the two?
Why do structs exist in C++?
The difference comes down to ______.
Cherno's Style Guide
When does he use structs?
Will Cherno use inheritance with structs? Why or why not?
Note: Cherno's guide is a pretty good set of guidelines. There's no absolute rule in industry on this, but what he's suggesting is pretty conventional.
Why is he writing a logging system as an example class?
What are his goals / features he plans to write for the log class?
Follow his example
What is the purpose of the m_ convention?
Why does he have public written twice?
How does the log level system work?
CONSTRUCTORS AND DESTRUCTORS
Define a constructor
When we instaniate the entity, what values did it have for x and Y? Why?
Vocab: These are called garbage values.
First solution is an "init" method. What's the problem with this solution?
Follow Cherno's syntax for creating a constructor. This should look very familiar from Java.
What happens if you don't specify a constructor?
In Java, primitive types are automatically initialized and set to zero. How is this different in C++?
Note: Notice that Cherno doesn't use the new keyword when creating the object. In C++, you only need to use that when you're manually putting it on the heap. But when you use new, you'll need to remove it manually too, using a destructor.
What syntax do we use to designate a destructor?
In the entity class, we don't need to manually remove the X and Y, since we didn't manually create it using new.
Why would you use a destructor?
What is a memory leak? (Google it!)
What does inheritance allow us to do?
Why is this useful?
Why not just copy the code from Entity into Player?
What is the syntax to make Player a subclass of Entity in C++?
Watch his example of inheritance in use. This should be familiar, it's the same as Java.
What is polymorphism?
How does Cherno show that Player is a superset of entity?
What is an array and why are they useful?
How do you declare an array of 5 integers?
Notice that this is different from Java!
How do you access an element of an array?
What happens when you try to output the array itself, rather than an index of the array?
How might you cause a MemoryAccessViolation with an array?
Why is this extremely dangerous?
How do you use a for loop to go through an entire array?
Why is there a performance hit for using a <= in a for loop?
What does Cherno mean when he says that arrays data is stored contiguously?
Be able to describe how indexing works.
Note: You won't need to replicate the pointer arithmetic on a quiz, but it's interesting to see the wild stuff you can do in C++ with pointers.
Arrays on the Heap
Cherno creates two arrays: one on the stack and one on the heap. Be able to briefly describe the difference in their lifetime.
How do you get rid of an array created on the heap?
Why would you allocate dynamically using the new keyword?
Standard Array in C++ 11
Why might someone want to use the "new" std array in C++ 11?
Note: C++ 11 came out in 2011. So it's not that new.
What basic feature we take for granted in Java is missing from the default array in C++?
How might you try to work around this limitation?
Example #1: sizeof
Example #2: constant
How do you create a std::array?
What's Cherno's take on raw arrays vs. std arrays?