C++ Programming Language

The "C++ Programming" course is designed for students who are familiar with at least one
"traditional" structured programming language (C, Pascal, Fortran, etc).
It means that we are not going to tell basics, such as variables, functions,
conditional operators, cycles, etc. We also assume that students know the
syntax of C programming language (students are supposed to learn in themselves).

There are two lessons per week: one lecture and practice lesson.
Approximate topics for lectures are in italic below.
For practice lessons each student needs a computer
with necessary software installed: Ubuntu
(or any other modern Linux distribution), gcc, Eclipse.

First semester

  1. C and C++ programming languages
    С++ — is (almost) superset of C. Possibility to write an efficient
    proram on C++. Main difficulty with programs on C++: direct memory management.
    Size of the C++ standard. Impossibility of covering all C++ in one course.

    Transformation of a code into a program: preprocessor, compilation and linking.
    What is checked during compilation and what is during linking.
    Structure of C/C++ program: source files and header files.
    What should we put into headers files, and what we can't.
    Macros instead of function: are bad idea. Using header guards for preventing
    header double inclusion. Dependencies between program parts. Makefile.

    Practice: simple program consisting of several source files and a header file.
    Makefile for such a program (with target 'clean').

  2. How program executes
    What is the result of code compilation. Structure of compiled program.
    Code segment, data segment. Runtime memory usage. Stack and heap.
    How are arguments passed to a function? Where are variables stored?

    Practice: control structures of C. Stages of the compilation process.

  3. Pointers and references
    Argument passing by pointer. Address of and dereference operators.
    Uninitialized pointers. Null pointer. Potential problems when using pointers.
    References. Similarities and differences between pointers and references.
    How references are stored.

    Practice: argument passing by reference and by pointer.
    Task: achieve segmentation fault.

  4. Heap memory allocation
    C: malloc/free. C++:
    new/delete and new[]/delete[].
    Why are there two ways of memory allocation? Potential problems.
    Efficiency questions. Two-dimension arrays.

    Practice: Achieve memory overflow. Allocate space for two-dimensional array using
    two different techniques. Compare times needed for every technique.

  5. С++ as "C with handy structures
    Encapsulation. Constructor and destructor. Array class with self memory management.
    Automatic destructor calls. Danger of unexpected program end. Again about differences
    between malloc/free and
    new/delete. Copy-constructor.
    Problems with assigning. How to forbid assigning.

    Practice: Class for array/two-dimensional array.

  6. C-style strings. Input/output in C and C++
    Built-in arrays and pointers. Strings. End of string symbol.
    String constants. Operations with strings.

    File descriptor, FILE. What does it mean to open/close a file.
    Buffering, flush/fflush. Standard files
    stdin, stdout, stderr.
    C++ streams for input/output: std::in, std::out,
    std::err (without explanation).

    Practice: file stream class using FILE (without operators).

  7. Class members
    Methods and fields. Access specification keywords. Why all fields must be
    private. Why it is useful. Efficiency problems.
    inline keyword. Which methods should be public?
    Class invariants. What programmer can optimize and what can be optimized by compiler.
    Optimization examples: never call a function twice.
    Code conventions.

    Practice: rational numbers stored in normal form.

  8. Initialization and const
    Potential problems: uninitialized variables.
    Initialization in constructor. Other problem —
    accidental change of a variable.
    Solution: const fields, const methods, const reference as a function
    parameter by default. Constant return value. "Transmissibility" of const.
    Reference as a return value. Paired methods: const/non-const.
    mutable keyword. this keyword.

    Practice: Array class, stream class for FILE.

  9. static keyword
    Static global variables.
    Static local variables.
    Static functions.
    Static class members.
    Static fields initialization.
    Code conventions.

    Practice: global constants. Addresses of global and static variables.
    Function calls counting. Class instance counting.

  10. Operator overloading
    Arithmetic operators. Assignment operator overloading. Special operators: [], (), etc.

    Practice: rational numbers with operators.

  11. Inheritance
    Idea of type extension. Problems with copying. Implicit type conversion.
    protected keyword. Again about access specifications.
    friend keyword. Comparison with Java.
    Infeasibility of complete protection in C++.
    Access specifications as a way of self-restricting.

    Practice: augment output stream with possibility to output
    rational numbers.

  12. Overloading and overriding. Polymorphism
    Method overriding. Don't misapply overloading. Constructor overloading.
    Complicated rules for overloaded function call. Static and dynamic typing.

    Overloading and overriding — different notions. Virtual methods.
    Pure virtual functions. Virtual functions table. Again about static and dynamic typing.
    Virtual destructors. Order of virtual functions table building.
    Danger of calling virtual methods from constructor/destructor.
    Why it's possible syntactically?

    Practice: augment stream class.

  13. Smart pointers
    Scoped smart pointer scoped_ptr (without templates).
    The same problem for arrays. Reference counting.

Second semester

  1. Templates, part 1
    Template functions and classes. Function parameters deducing.
    Template methods and constructors.
    Compilation of templates. Why templates should defined be inside header files.
    Default arguments. Usefulness of typedef.
  2. Templates, part 2
    Template specialization. Difference between specialization and overloading.
    Partial specialization. Non-type template parameters.
    Using of dependant names (typename keyword).
  3. STL, sequence containers
    General STL ideas. Iterators instead of indices.
    Use of sequence containers: vector, list, deque.
  4. STL, associative containers
    Use of associative containers: map, set.
    multi- versions of associative containers with non-unique
    elements. User-defined element order.
  5. STL, adaptors and iterators
    Container adaptors. Iterators categories. Reverse iterators.
    Iterators requirements. How to write your own iterator.
    Idea of iterator_traits.
  6. STL, algorithms
    Requirements for elements and sequences in algorithms.
    Algorithms for any sequences.
    Algorithms for ordered sequences.
    Algorithms modifying sequences.
    Other categories of algorithms. How to write your own algorithm.
    How to specialize algorithm for specific type of iterators/elements.
    User-defined predicate and functors.
  7. Pointers to functions, methods and class fields
    Function pointers. Method pointers. Class fields pointers.
    Using function pointers as functors.
    Listener pattern.
  8. Namespaces
    Namespace definition. Global namespace.
    using keyword. Name look-up. Koening look-up (ADL).
    Again: name look-up and class inheritance.
  9. Exceptions
    Concept of exceptions. Standard classes of errors. Exception specification.
    Strategies of error handling. Why we must not to throw build-in types.
    Exceptions in constructors. Exceptions in initialization list.
    Prohibition of exception in destructors.
  10. Exception safety guarantees
    Exception safety guarantees. When it's feasible to provide string exceptions
    safety guarantee. Use of swap for exception safety.
    Use of auto_ptr for exception safety.
    Program design accounting exception safety.
  11. C++-style type conversions С++ and RTTI
    C++-style type conversions: static_cast,
    const_cast, reinterpret_cast,
    dynamic_cast. Advantages of C++-style type conversions
    in respect to C-style. When C-style conversion fails to replace
    C++-style (multiple inheritance).
  12. Boost library
    Smart pointers, string algorithms, iterators.
    Using boost to write platform independent code.
    Libraries for functors definition: bind и lambda.
  13. Metaprogramming на C++
    SFINAE и enable_if.
    Compile-time checking whether one class is an ancestor of other.
    Algebraic data types on templates.
    MPL library from Boost.
  14. Standard C++11
    New features of C++.