0% found this document useful (0 votes)
8 views

C++ Summary sheet

The document outlines key concepts in object-oriented programming (OOP) using C++, including the structure of header and implementation files, class attributes, methods, constructors, destructors, and access modifiers. It also covers file I/O, exception handling, version control with Git, and advanced topics like static methods, templated functions, iterators, and the build process with dependencies. Additionally, it introduces GoogleTest and SFML for testing and multimedia functionality.

Uploaded by

avereese
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

C++ Summary sheet

The document outlines key concepts in object-oriented programming (OOP) using C++, including the structure of header and implementation files, class attributes, methods, constructors, destructors, and access modifiers. It also covers file I/O, exception handling, version control with Git, and advanced topics like static methods, templated functions, iterators, and the build process with dependencies. Additionally, it introduces GoogleTest and SFML for testing and multimedia functionality.

Uploaded by

avereese
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Lecture 1

Making instances/calling methods


a. OOP basics through it
a. h/cpp split Making instance Calling methods
i. .h files (header files) contain declarations of classes, functions. ClassName obj; Obj.method();
ii. .cpp files contain definitions (implementations)
b. instance attributes, normal methods

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

File I/O using fstream Stringstream(have to


Reading from file Writing to file include<sstream>
Std::ifstream file(“filename.txt”); Std::ostream file(“filename.txt”); -allows us to build a string (<<)
Std::string line; File << “Hello, File” << std::endl; and read from a string (>>)
While (std::getline(file, line)) { File.close(); Std::stringstream ss;
Std::cout << line << std::endl; Ss << “123”;
} Int num;
File.close(); Ss >> num;

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

Exception throwing and handling


Throwing exception Handling exception
Throw std::runtime_error(“error message”); try{
PD.add_person(temp_person);
} Basics of std::vector and comparison to our
catch (std::runtime_error e){ ArrayList class
std::cout << e.what() << "\n"; -Both use .size() and .capacity(), they are
} declared similarly, able to access elements
using [] or .at(), and we can you for each
loops for both.
Basics of version control using Git/Github -We have something similar to the push_back()
Allows us to track changes, have a history of our changes, function (append())
allows branches and merging and collaboration. -We do not have pop_back() which removes
the last element.
Lecture 2

Static methods and


Improved array-allocation scheme (append/prepend/insert/clear/remove) attributes
grow shrink Shared by all instances of
a class. Static member
variable belongs to the
class itself, not to any
specific object

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

How to make an Make iterator class ->


iterator for a custom implement operator++ -
type (and support for- >operator* ->operator!= ->
each loops? begin() -> end()

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)

c. Initializer-list and move constructors

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

You might also like