Key Things Flashcards
What are the principles of OOP?
- Information / data hiding
- Encapsulation
- Abstraction
- Modularization
Encapsulation goes hand-in-hand with what?
What about modularization?
Encapsulation goes hand-in-hand with information hiding.
Modularization with low coupling and high cohesion
What are the basic elements of a C++ program?
Classes, methods, and data members
How are these different:
#define constant
const constant
constexpr constant
define constant - preprocessor definition that does a simple replacement during preprocessing and before compiling
const constant - names constant declaration where the programmer commits to not changing a value
constexpr constant - constant expressions evaluated at compile time, allowing them to be places in read-only memory
What is the difference in visibility between a struct and a class?
struct - default public
class - default private
In what ways are things allocated on the heap?
By using the malloc() function or using ‘new’
What are the advantages and disadvantages C++ having no garbage collection?
Advantages: performance
Disadvantages: cumbersome, error-prone, memory leaks, painful
Can void pointers be dereferenced using “*”?
No
Functions must be ___ before they are ____?
Functions must be declared before they are called
How does C++ allow for pass by reference?
By supplying the ‘&’ in front of the parameter:
void Two (int& x) {
x = 2;
cout «_space;x «_space;endl;
}
Why is it poor-form to use the ‘declaring namespace’ syntax in a header file?
Because it can lead to inadvertently opening up access to namespaces in unanticipated ways, leading to name collisions and other problems
Classes are an expanded concept of what?
Structs
What are private, public, and protected access specifiers for class members?
private - accessible only from within other members of the same class
public - accessible from anywhere where the class and its instantiated objects are visible
protected - accessible from other members of the same class and members of their derived class
What is the difference between the following two:
ObjectType *obj1;
ObjectType obj2;
obj1 is a pointer and therefore not instantiated without calling the ‘new ObjectType’ on it.
obj2 is instantiated
If an access specifier is not provided when inheriting from a base class, what is the default?
private