A short introduction to C++ - Advanced

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

Allocating memory at run-time with new:

Operator delete releases dynamic memory previously allocated with new.

A common problem in programs is a memory leak:


Part 1. Namespaces

Single global namespace is often a bad idea.


Part 2. Using functions

2. Function overloading (函数重载)

Often algorithms have different implementations with the same functionality. Overloaded functions have the same name, but different argument lists.

3. Passing Arguments

3.1 Pass by value, reference and pointer

3.2 Passing arrays as function parameters


Part 3. Classes

4. Constructor, member function, destructor

A class representing a vector in 2-D.

5. Inheritance (继承)

Inheritance is a technique to build a new class based on an old class.

6. Virtual function (虚拟函数)

Often derived classes behave differently. Virtual functions make runtime polymorphism possible.


Part 4. Organize codes into modules

Usually it is not convenient to keep all C++ source code in a single file.

7. Typical layout of a module