Term
How do I compile a main.cpp file? What is in a main.cpp file? |
|
Definition
g++ -Wall filename.cpp -o filename ./filename
int main() { return 0; } |
|
|
Term
4 properties of each variable |
|
Definition
type, name , value, memory location |
|
|
Term
|
Definition
Idea of having an "API" in .h file and "implementation" in .cpp |
|
|
Term
3 things about a default constructor |
|
Definition
Provided automatically No parameter Initialize class value to default values. |
|
|
Term
Alias variables, example and description
int i = 7; int &j = i; j = 4;
i is equal to?? |
|
Definition
Like having two different names for a variable.
Output: Also 4, takes value from j. |
|
|
Term
What does &c return (type)? |
|
Definition
A memory address of c's data. |
|
|
Term
|
Definition
Return a pointer to a stack variable. |
|
|
Term
Passing by value into a function |
|
Definition
*Default *Makes a copy of the varable *Slow |
|
|
Term
Passing by pointer into a function |
|
Definition
*Passing memory address * Fast(8 bytes) |
|
|
Term
|
Definition
Not a lot copied, just an alias, fast, better version of pointer. |
|
|
Term
Proper way to pass (best way) into a function
Fix: Cube doSomething(Cube c1) |
|
Definition
const reference
Ex:
Cube doSomething(const Cube & c1); |
|
|
Term
Auto Copy Constructor, two things |
|
Definition
Generated if we do not define a copy constructor
Copy every instance variable in the object |
|
|
Term
|
Definition
ALWAYS pass by reference
Cube(const Cube & other) {...} |
|
|
Term
|
Definition
Must have the variable intitialized Cannot be changed. |
|
|
Term
Construction Initializer List |
|
Definition
Initialize variables.
Add this after construcutor -
:local variable name(local varaible name), ...
Example:
Tower::Tower(const Tower & other) : cube_(other.cube_), ptr(other.ptr_), ref_(other.ref_) |
|
|
Term
Deep copy cube (by value, in copy constructor that has an other.cube_) |
|
Definition
|
|
Term
Deep copy a Cube pointer ptr_ |
|
Definition
ptr_ = new Cube(*other.ptr_)); |
|
|
Term
Deep copy a Cube reference ref_ |
|
Definition
Add it to a constant copy constructor by using : ref_(other.ref_) |
|
|