Multi-file programming include rules

xiaoxiao2021-03-06  86

In C , habit declarations and definitions are separated, that is, a class of Class corresponds to two files, one .h, one .cpp. When we face multiple classes, file include INCLUDE may need to pay attention. I have no more experience in this, so I have a little loss. Summarize a little experience:

1. MyClass.h This file only places a declaration related to MyClass without placing a statement of the class that may be used in MyClass, or other .h introduction.

Add #pragma overce in MyClass.h

Or add a #ifndef _xxxxxx_h_ # define _xxxxxx_h_

....

#ENDIF

To ensure that the statement is only #include once.

2.myclass.cpp

The first include section of each class.cpp is divided into two parts. The first part is the whole class library .H of include; the second part is the include library in addition to the entire class library.

// public part # include "myclasslibcommon.h"

// private part # include "myclassbase1.h" #include "myclassbase2.h" #include

3.MYCLASSLIBCOMMON.H

This file places a declaration section of the entire class library, and some system libraries that everyone can use. #include #include #include

#pragma comment (Lib, "WSOCK32")

Using namespace std;

Typedef unsigned int dord; typef unsigned short word; type;

4. Myclasslib.h This file is set for the external program reference. It references all classes in the library. // The first part #include "myclasslibcommon.h" // second part #include "myclass.h" #include "myclassbase1.h" #include "myclass2.h"

5. app.cpp In this file, you need an IclassLib.h file that you need to include. The entire Project can be compiled.

转载请注明原文地址:https://www.9cbs.com/read-107284.html

New Post(0)