- Why do we need classes, why can’t we just use structs?
Because more complex data types are often not easily handled in structs. Structs don’t have all the same memory allocation properties that classes do.
- What are methods?
A function or a procedure dedicated to a class.
- How would you define a class?
class myClass {
private
// fields
public
// fields
methods
void myFunction();
};
- What is an object?
An instance of a class. Classes represent data types, but an instance of a class must be declared in memory. One class can be made into several objects of the same class. Once you have a class defined, you can inherit it’s methods and properties by defining a class of another class. This avoids the necessity for code duplication.
Objects allocate memory and it’s important to remember that any objects that you create must also be freed or one can have memory leaks. This is the case in Pascal, but so far in C++ in the course, this issue hasn’t been addressed.