Created
June 4, 2017 00:40
-
-
Save caviles/fa24f1c4742613ded3f0a61e7e3e9965 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C++ templates are set at compile time not runtime like C#, java | |
//returns max of two values | |
template <class T> | |
T max(T& t1, T& t2){ | |
return t1 < t2 ? t2 : t1; | |
} | |
overload operators in c++ often | |
instead creating a Add() overload + and or += | |
in a class f you don't specify the default is private in a struct the default is public | |
C++ style guide | |
https://google.github.io/styleguide/cppguide.html | |
enum e_acomany { | |
Audi, | |
BMW, | |
Cadillac, | |
Ford, | |
Jaguar, | |
Lexus | |
Maybach, | |
RollsRoyce, | |
Saab | |
}; | |
e_acompany my_car_brand; | |
my_car_brand = RollsRoyce; // notice you don't do e_acomany. so decorate the enum name around the member | |
if (my_car_brand == Ford) | |
cout << "Hello, Ford-car owner!" << endl; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cons of manual memory management
-delete twice - error
-never delete - memory leak