C++ Notes

Declaration and Definition

Declaration: use extern to declare a variable.

Definintion: int i; is a definintion. extern int i = 10; is also a definintion.

Note that it is an error to provide an initializer on an extern inside a function. Because variable with extern is global. extern with initializer in a function is a temperary variable, not a global variable.

Seperate Compilation

Use #define #ifdef #ifndef #endif to make sure that head file can be included only once.

Name Lookup & Type Checking

In C++, name lookup happens before type checking. So, variable and function cannot have the same name.

inline Function

We should define inline functions in headers, and inline member functions should be defined in the same header as the corresponding class definition.

in-class Initializer

in-class initializers must use either the = form of initialization or the direct form of initialization using curly braces.


电子邮件地址不会被公开。 必填项已用*标注

13 + 15 =

17 − = 7