You are on page 1of 2

C++ - Things I need to refresh

Memory Trick & Address of ip = &i; read it as ip equals the address of i * Contents of j = *ip; read it as

j equals the contents of ip

* Pointer Declarations are different when it comes to the * int *ip; read it as integer pointer ip References A reference is an alias to a variable, not a pointer, not a copy, C++ feature (newer ANSI C) int actualint = 6; int & refInt = actualint; this-Pointer The this pointer is a way for the code in a member function to refer to itself (the object) Virtual Functions By declaring a virtual functions the parent is giving the child a TO DO list (optional) Abstract classes are classes that do not and will never have a direct object instance. Pure virtual functions are like abstract functions, they are required otherwise the compiler will not compile (required) Friend Functions Friend Functions, Allow a specific member function in another class access to private data Template Syntax template <class T, class S > void LinkedList<T>::AddEntry(T &entry) { // ... } template<class T> T min(T& a, T& b)

Throwing Error Objects Real OOP error handling demands throwing objects, not int's or char *'s

class Slap { }; class Scream { static char *yell = "Ewww, don't touch me"; }; int fake_a_yawn() { if (just_friends) throw Slap; if (stranger) throw Scream; //... otherwise keep going return 0; } try { // do something risky int signal = fake_a_yawn(); // .. keep going if it works } catch (Slap) { // catch the error object } Unexpected Exceptions There is a 'catch-all' catch (...) { // three dots (periods) says to catch EVERYTHING (except Slap) } Standard Template Library (STL) The 3 main components of the STL are: Containers: data structures that hold information (like an array does, only better) Iterators: Allow you to loop through all the items in a container ( looping trough an array 0 to length) Iterators allow you to access the items in a container Algorithms - Functions that allow you to search, sort or compare container elements. Since containers can hold objects of different types, less need to write a new sort function for every kind of object. Remember, templates create classes, classes build objects and objects have functions that operate on their data. There is a set of functions that all objects built through STL will have.

It is like a better array Dynamic type casting try { cr = dynamic_cast<Circle &>(sr); } catch (bad_cast) { cout << "Circle, We ain't got no stinkin' Circle"; } dynamic_cast is used strictly for type casting between parent and child (or base and derived) classes. Its, big advantage is it does run time error checking.

You might also like