A short introduction to C++ - Advanced

Part 0. Dynamic memory allocation (动态内存分配)

 

Part 1. Namespaces

Namespaces and the Standard Library

Part 2. Using functions

1. Default arguments

in C++ functions, arguments can have default values

2. Function overloading (函数重载)

Often algorithms have different implementations with the same functionality, overloaded functions have same name, but different list of arguments.

3. Passing Arguments

  1. pass by values

output:

  1. pass by references

output

  1. pass by pointers

Output:

  1. Passing array as function parameters

 

Part 3. Classes

4. Constructor, destructor

A class representing vector in 2-D.

  1. Constructor (构造函数)

  1. Member function(成员函数)

  1. Pointers to objects

  1. Information hiding

    • Public data

    • Access is unrestricted. Situation identical to no access control declaration

    • Private data

    • Data objects and member functions in the private section can only be accessed by member functions of the struct (which themselves can be either private or public)

  1. Destructor (析构函数)

Example with automatic File object

5. Inheritance (继承)

 

 

Part 4. Organize codes into modules

6. Typical layout of a module

- Safeguarding against multiple inclusion in .hh

7. Makefiles