Sie sind auf Seite 1von 4

Types of Programming Procedural = functions Object-oriented = classes Generic programming = templates, typedefs Struct - members public by default, used

for data Class - members private by default, used for objects with non-trivial methods Scopes: global, namespace, class, function, block Namespaces: good for large function collections and general purpose collections Declarative region - where a var/function can be declared Potential scope - where a var/function can be used Strings C-style: contiguous arrays of char (char *) C++: provides rich set of overloaded operators char * w = world; string sw = world; char * h = hello, ; string sh = hello, ; cout << (h < w) << endl; // 0: why? cout << (sh < sw) << endl; // 1:why? Is this because the pointer h has a greater value than w, but sh is alphabetically less than sw? cin >> i cout << You said << i << endl; ifstream ifs (in.txt); if (ifs.is_open ()) { string line_1, word_1; getline (ifs, line_1); istringstream iss (line_1); iss >> word_1; cout << word_1 << endl; } int i; int & r = i; int * p; int * & q = p; cout << &i i is an integer r is a reference to an integer (initialized with i) p is a pointer to an integer q is a reference to a pointer to an integer (intialized with p) 0x23kde00

Fish f; Fish * fp = f; Fish * fp = &f;

// can you say this? // or have to say this?

4 member functions defined by compiler: default constructor, copy constructor, assignment operator, and virtual destructor Polymorphism Liskov Substitution Principle - if S is a subtype of T, then wherever you need a T you can use an S Abstract Class (cant instantiate) class AB { public: virtual void f() = 0; }; Use abstract base classes to declare interfaces Use public inheritance to make sets of polymorphic types Use private inheritance only for encapsulation Design Patterns Factory Method -- polymorphism & abstract methods Adapter (structural) Converts an interface you have into one you want Memento (behavioral) Externalizes the state of an object (for cookies) Observer (behavioral) Tells objects about changes in another object

However, actual types of objects aliased by references & pointers to base classes vary dynamically (at run-time)

Header files declarations: promises made to the compiler Makefile compiles files according to inference rules (theres one default in VS08) Life-cycle of a C++ program precompiler #commands such as #include, #define, #ifndef/#endif

compiler (syntax) functions must take correct number and types of arguments each source file is compiled independently, which is why you must #include in each file. passes an object file to the linker linker detects duplicate or undefined definitions, or inconsistent use of const produces a .exe program executable program

C++ vs C-style strings cstr() to convert C-style contiguous arrays of chars with \0 char on end C++ provides rich set of overloaded functions use whenever you need to change, concatenate, or manipulate in any way C++ FIle I/O Stream Class fstream, ifstream, ofstream dont have to call fs.close() as long as the destructor of the object is run istringstream / ostringstream = means initialization when used with a type declaration otherwise, its an assignment & means a reference/alias when used inside a type declaration otherwise, means address of -> access member variables via pointer if left side is pointer, lets you call something directly see slide Whats a pointer? const pointer means you cant change the variable via the pointer read-only access int const *p = &temp; makes pointer const

Das könnte Ihnen auch gefallen