extern int i;//declares but does not define i
int i(0);//declares and defines I, init i as 0
extern int i=1;//initial i as 1
Can declares multiple times, but only can define one time.
Const key
const object cannot be modified so that it should initial when it was defined.
//file_1.cc
int counter;//uses counter form file_1
//file_2.cc
extern int count;//use counter from file_1
++counter;//increase counter defined in file_1
//file_1.cc
//defines and initializes a const that is accessible to other files
Extern const int bufSize=fcn();
//file_2.cc
Extern const int bufSize;//uses bufSize from file_1.cc
//uses bufSize defined in file_1
For(int index=0;index!=bufSize;++index)
//…
Typedef
typedef double wages;
wages hourly, weekly;
Enumeration
enum open_modes{input, output, append};
Enumeration member's value is a constant expression
enum Points{point2d=2, point2w, point3d=3, point3w}:
Interface and Implementation
Default access level: struct is public, class is private;
Header file(.h)
.h file is used for declaration, but not definition.
Some const object defined in header file
Header Guard(Preprocess defined)
#ifndef TEST_H
#define TEST_H
//Definition of Test class and related functions goes here
#endif
Terminology:
Access label
Address
Arithmetic type
Array
Byte
Class
Class member
Compound type
Const reference
Constant expression
Constructor
Copy-initialization
Data member
Declaration
Default constructor
Definition
Direct-initilization
Enumeration
Enumerator
Escape sequence
Global scope
Header
Header guard
Identifier
Implementation
Initialized
Integral type
Interface
Link
Literal constant
Local scope
Lvalue
Magic number
Nonconst reference
Nonprintable character
Object
Preprocessor
Private member
Public member
Reference
Run time
Rvalue
Scope
Separate compilation
Signed
Statically typed
Struct
Type-checking
Type specifier
Typedef
Undefined behavior
Uninitialized
Unsigned
Variable initialization
Void type
word