C++ Summary sheet
C++ Summary sheet
i.
instance attributes are variables that are defined inside a class. They are typically initialized in the c’str.
ii.
Normal methods are functions that are defined inside a class to operate on its attributes
Constructor Destructor
cin cout
Def: special method for Def: cleans up
Used for getting input from the Used for outputting things to the
object initialization when the object
user console
goes out of scope
std::cout << "\tEnter Hourly Rate: ";
ClassName() ~ClassName()
float temp_rate;
{…c’str code…} {…d’str code…}
std::cin >> temp_rate;
C++ strings
Access Modifiers Objects of the std::string class (have to
include <string>)
public private protected
Have to include iostrem
Accessible from Accessible only within Accessible within
anywhere the class the class and Example:std::cout << “example \n”;
derived class
Project Reorganization
Dynamic obj and array allocation + connection to arrays Include - .h files
new delete Dependencies - .dll
Allows us to create a new array. Allows us to delete an array Bin - .exe
Ex: int* arr = new int[10]; Ex: delete[] arr; Build - .sln, .vcxproj
Src - .cpp
Templated functions
-Functions that work with any
data type.
-Example: template <class T>
-Void print (T x) {}
Const-references and the connection to const-safe methods
Const-reference Const-safe methods connection
A reference to a variable Methods that They both
that cannot be modified guarantees not to provide read-
through the reference modify the state of the only access by
Templated classes Ex: void object. not letting the
-classes that can work with MethodName(consttype& Ex: Type MethodName() data be
any data type variable){} const {} modified.
Compare/contrast ptrs and ref’s
references pointers
Alias to another Holds memory address of
variable ( a variable (holds address of)
reference to a Example:
variable) Int* ptr = &a;
Example:
Int a = 10;
Int& ref = a;
Lecture 3
Iterators in std::vector
Used to traverse elements Connection to for- Why are iterators a thing? Connection to find and erase
in std::vector each loops
Ex: -uses iterators - gets rid of having to use pointers, can - std::find returns an iterator to the found element
Std::vector<int>::iterator it; internally just use iterators to access elements or end() if not found
-for(int x : y) {} instead of pointers - erase removes an element using an iterator.
- iterators include boundary checks
unlike pointers which reduces risk of
accessing invalid memory
a. Friend statement
a. Have to declare a class that you want to make a friend inside the class you want it to be the friend of.
b. friend std::ostream& operator<<(std::ostream& os, const ArrayList& o_list)
b. Copy constructors (and =operator)
Lecture 4
a. The build stages and how they relate to adding a new dependency (like GoogleTest)
a. And how CMake (or similar) fits into this process
i. Make a build and sdk folder.
ii. Select main folder for source folder and build folder for build
iii. Click configure
iv. CMAKE_INSTALL_PREFIX(sdk folder), BUILD_SHARED_LIBS(enable), create
CMAKE_DEBUG_POSTFIX(string) and set It equal to “_d”,
BUILD_SHARED_LIBS(sfml) then configure and generate.
v. Open the sln, right click solution, batch build, select ALL_BUILD and INSTALL
for debug and release.
b. Basic GoogleTesting
c. Basic SFML