asdfasdf http://www.google.com hello world: #include using namespace std; int main() { cout << "Hello World!"; return 0; } compile: g++ comments: /* */ // variable initialization: int a = 0; int a (0); constants: decimal: 75, 75u, 75l, 75ul octal: 0113 hexa: 0x4b floating point: 3.12, 5.34e223, 1.3e-23, 3.0 3.13L, 6.04e34f char: 'e' string: "asd" of wchar_t: L"asd" for other character sets bool: true, false defined: #define ASD val preprocessed declared: const int a = 334 like normal vars, but cannot be modified operators: comma operator: a=(b=3,b+2) int a = sizeof(char) strings: #include string s = "asd"; char s[] = "asd"; char* s = "asd" input/output/i/o/stdio iostream: #include #include cout << "hello" << endl; new line: endl int age; cin >> age; cin >> mystring stops on blank getline(cin, mystr) stringstream: #include getline(cin,mystr) stringstream(mystr) >> quantity; separate obtaining input with interpretation of input control structures: if, else, else if, while, do-while, for, break, continue, goto exit: cstdlib, switch functions: void by value: asd (int a, int b) by reference: asd (int& a, int& b) overloading with different signature inline type name (args) { instructions } prototype declaration: type name (args) arrays: type name[elements]; as argument: (int arg[], int arg2[][depth][depth]) special case: const int n = 1000; int a[n] pointers: reference operator: address of pointer = &var dereference operator value pointed by var = *pointer decl: int* p; set directly: int n int* p = &n; means NOT *p = &n, but means p = &n multiple: int* p1,* p2 ! difference between pointers and arrays: arrays are CONSTANT pointers to the first element a[5] is equivalent to *(a+5) int n[20]; int* p; p = n; is valid n = p; is not pointer arithmetic/precedence p++ increases the value of sizeof(typeof(p)) *p++ === *(p++) === *p; p++ because postfix pointers to pointers char** c void pointers pointers to a value with not type can point to anything data can not be dereferenced null pointer int* p = 0; points to nowhere pointers to functions rettype (* fp)(argtypes) = fname rettype res = (* fp)(args) dynamic memory: p = new type p = new type[n] n doesn't have to be constant here int* bobby = new int[5]; allocated in heap exceptions: default: bad_alloc exc p = new (nothrow) int[5]; if error just returns a nullpointer delete pointer delete[] pointer in c: malloc, calloc, realloc, free also available data structures: struct sname { mtype1 membername;...} objnames; sname objnames; obj.member pointers to structures: sname* obj; obj->member === (*obj).member *obj.member === *(obj.member) additional data types: aliases/synonyms typedef existingtype newtypename; unions: union uname {members} anonymous unions inline struct { type el; union {type el1; type2 el2 }} enumeration: enum enumeration_name {membe[=startval],member...} objnames; compatible with integers classes: holds data and functions class cname {access_specifier_1: member1;...}objnames; note: different syntax than java access specifiers: private: same class or friends (default) protected: same or derived class public: all instantiate Cname v; Cname v(args); NOT Cname v(); methods: can be overloaded (with other args) Cname::mname (args) {} scope operator :: varname directly constructor: Cname::Cname (args) {} java's super: SubCname::SubCname (args) :Cname(args) {} destructor: Cname::~Cname() {} pointers to classes: Cname* o = new Cname; o->mname(); struct and union classes is possible, difference: struct public by default this: pointer to current object static members: class variables static int n static function: can only refer to static data no this operator overloading: operator function: member function: CVector CVector::operator+ (CVector param) {} global function: CVector operator+ (CVector param, CVector param) disadvantage: cannot access private friendship friend function: class C {...;friend type function (args);} friend class: friend class Cname if cross ref needs empty definition first not transitive inheritance: class Cname: public Pname1, public Pname2, ... described minimum access level for members inherited inherits everythin except constr,destr, operator=(), friends polymorphism: classes conform to base classes virtual members/polymorphic class: virtual type mname() {} can be redefined in lower classes: int mname() pure virtual function/abstract class: virtual int mname() =0; genericity: function templates: declare: template fdecl; use the identifier as a type inside use: fname (params); multiple: class templates: typetype: class or typename template class Cname { member functions: template rettype Cname::mname(...) {...} instantiate: Cname var; template specialization: existing: template class Cname { specialization: template <> class Cname { define all its members: no inheritance non type parameters! template defaults: t use with t<> compiler: compiled on demand bound genericity? namespaces: define: namespace identifier {entities} include: #include using namespace identifier; use: using identifier::entity identifier::entity or using namespace identifier; avoid name clashes with {} aliases: namespace nname = name; exceptions: try {} catch (int e) {} ellipsis: catch(...) throw 20; limit exception type of function: rtype fname (args) throw (type); no exc allowed: throw() all exc allowed: empty standard: in namespace std, header exceptiono bad_alloc, bad_cast, bad_exception, byd_typeid, ios_base::failure type casting: @ The C++ language tutorial, p. 127 sdl: gui