CS 541 Lecture -*- Outline -*- * C++ refs: Stroustrup, The C++ Programming Language, and HOPL II ** History Designed by B. Stroustrup at ATT Bell Labs influenced by from C and Simula 67 C is a subset ----------------- C++ HISTORY 1980 Stroustrup's C with Classes event driven simulation projects 1985 Stroustrup's C++ book 1989 2.0 version of C++ multiple inheritance, better access control, type-safe linkage 1992 3.0 version of C++ templates ----------------- ** Goals ----------------- GOALS "provide Simula's facilities for program organization together with C's efficiency and flexibility for systems programming" (Stroustrup in HOPL II) "make programming more enjoyable for the serious programmer" ("The C++ Programming Language") - program organization: Classes, inheritance, concurrency, static type checking based on classes - efficiency: programs as fast as BCPL (C), easy separate compilation - portability: highly portable, available from many vendors no complicated run-time support - support for many styles of programming -------------------- ** Derivation from C -------------------- C++ vs. C ANSI C is a subset of C++, except: - 'c' is a char, not an int - scope rules extend to nested structures structs are nested scopes - functions must be declared before use - only new-style function decls. - global data defined exactly once - no implicit cast from void* - jumps can't bypass initializations - global const's are 1 per file - the type of an enumerator is not int - types must be consistent, even in separate files - no surplus chars in string initializers -------------------- since contains C as a subset, is a hybrid object-oriented language don't have to use object-oriented features ** C++ support for object-oriented programming ---------------------- C++ SUPPORT FOR OOP - classes = information hiding this (for self reference) virtual (dynamic binding) public, private, protected friends scope resolution operator :: - (multiple) inheritance ------------------ ** C++ as a better C ------------------ C++ AS A BETTER C Features later adopted by ANSI C: - function prototyping - void* type - constants - volitile Other non-OO features: - templates - exception handling - type-safe linkage - operator new for allocation - overloading - default argument values - references, call by reference - // comment syntax - can declare linkage to non-C++ code ------------------