A, C + + file structure
C++/C the header file of the program with ". h" as the suffix, the C program's definition file with ". C "for suffix, C + + program
The definition file is usually a ". cpp" suffix
(1), header file structure (*.h):
The header file consists of three parts:
(1) The copyright and version statement at the beginning of the header file.
(2) pretreatment block.
(3) Function and class structure declaration, etc.
In order to prevent the header file from being repeatedly referenced, the IFNDEF/DEFINE/ENDIF structure should be used to produce a pre
Processing blocks.
Use the #include <filename.h> format to refer to the header file of the standard library.
Use the #include "filename.h" format to refer to a header file for a nonstandard library.
eg
#ifndef Graphics_h//Prevent Graphics.h from being repeatedly referenced
#define Graphics_h
#include <math.h>//reference header file for standard library
#include "myheader.h"//reference to a header file of a nonstandard library
void Function1 (); global function declaration
Class Box//struct declaration
{
};
#endif
(2), define the structure of the file:
Definition of copyright and version statement at the beginning of a file
A reference to some header files.
The implementation body of the program (including data and code).
#include "graphics.h"//reference header file
The implementation body of global function
void Function1 (?)
{
}
Implementation body of class member function
void Box::D raw (?)
{
}
Second, the name:
"Rule 3-2-2" variables and arguments are grouped by words that begin with a lowercase letter.
For example:
BOOL Flag;
int DrawMode;
The "rule 3-2-3" constants are all uppercase letters, with underscores separating the words.
For example:
const int MAX = 100;
const int max_length = 100;
The "rule 3-2-4" static variable is prefixed with S_ (representing static).
For example:
void Init (...)
{
static int s_initvalue; static variables
...
}
Rule 3-2-5 If a global variable is required, prefix the global variable with g_ (representing global).
For example:
int g_howmanypeople; Global variables
int G_howmuchmoney; The data members of the global variable "rule 3-2-6" class are prefixed with m_ (representing member), which prevents data members from
The parameter of the member function has the same name.
For example:
void Object::setvalue (int width, int height)
{
M_width = width;
M_height = height;
}
The Changvichang amount is used to represent numbers or strings that will appear multiple times in the program. Constants that need to be supplied externally are generally placed in header files. Do not need to publish the header on the definition file. const int MAX = constant in class 100: Const data members cannot be initialized in a class. Class A {const int SIZE = 100; int array[size];
the//error class object was not created and the compiler does not know the size value. }
The const data member can only be performed in the constructor initialization list. Class A {a (int size); const int SIZE; }
Call: A A (100)
You can use an enumeration type to establish constant constants in the entire class. Class A {enum {SIZE1 = m, SIZE2 = 200};//enumerated constants. int ARRAY[SIZE1]; int array[size2]; }
Third, function design