0% found this document useful (0 votes)
53 views2 pages

Midterm Cheat Sheet

Uploaded by

austynan
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)
53 views2 pages

Midterm Cheat Sheet

Uploaded by

austynan
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

Vectors IMPORTANT

● Dangling pointers (dereferenced?)


● Local pointers deleted?
● In bound?
● Violates interface?
● Initialize list?
● const call on a const?

Pointers
● Have their own space in memory
● Dangling: ptr holds an address but memory there has
already been freed; ptr points out of scope
○ NOT an undef. until dereferenced
● **ptr points to the location of *ptr2 and not what ptr2
is pointing to

References
● Exact same as the variable under another name
● When you see “&”, then it’s referring to the address

String
● Default constructor makes “ ” string

Casting
Const ● stoi(str): string to int
● stod(str): string to double

I/O
● getline(istream &is, string &str)
● ifstream someVar(“string”): >>
● ofstream someVar(“string”): <<

Overloading
● friend inside class to access private variables
● ostream& operator<<(ostream &os, const Object &o)
● bool operator==(const Pixel &p1, const Pixel &p2)
I/O
Classes
● Constructor call on a derived class NEEDS to call
base class constructor
○ Default (no parameters)
○ Explicit initialization list using “ : ”
● Bird:: Bird(smt) : Animal(smt), species(someBird) {}
● Must use function in derived class if not base class of
object

Overriding
● virtual: runtime polymorphism
● dynamic dispatch: depends on object on runtime
● override keyword at end of function header in derived
class
● Animal *a = new Dog()
○ All dogs are animals
Classes
Set
● set<type> varName
● varName.insert(element)
● varName.erase(element)
● varName.clear() // set
● varName.find(value) // returns pointer
○ .end() if not found
● varName.size()
● varName.empty()
● Ordered, non-repeating elements

Map
● map<key, value> varName
● varName[key] = value
Arrays ● varName.first
● varName.second
● iterator find(const key_type &k)
○ Get an iterator to the entry, or an end iterator
if it doesn't exist.
● pair<iterator, bool> insert(const pair<key_type,
value_type> &p)
○ Attempt to insert a new entry if the key is
unused. If successful, returns an iterator to the
new entry and the value true. Otherwise,
returns an iterator to the existing entry for the
key (i.e. the one that blocked the insert) and
the value false.
● Value_type& operator[](const Key_type& k);
○ Get a reference to the value stored for a key. If
it doesn't exist, insert default 0.

Pair
● pair<key, value> p
● p.first, p.second

Austyn Nguyen
FA24 EECS 280 Midterm Note Sheet
10/28/2024

You might also like