对话框程式.
是这样的:
我在SocketSend类中引用了myh.h头文件,然后又在prcess类中也引用了myh.h.
编译可以通过,但link时出现如下错误.
--------------------Configuration: MyClient - Win32 Release--------------------
Compiling...
MyClient.cpp
MyClientDlg.cpp
Generating Code...
Linking...
SocketSend.obj : error LNK2005: "struct probebuff gProbeBuff1" (?gProbeBuff1@@3Uprobebuff@@A) already defined in process.obj
SocketSend.obj : error LNK2005: "struct probebuff gProbeBuff2" (?gProbeBuff2@@3Uprobebuff@@A) already defined in process.obj
SocketSend.obj : error LNK2005: "struct _RTL_CRITICAL_SECTION gCriticalSectionForBuff" (?gCriticalSectionForBuff@@3U_RTL_CRITICAL_SECTION@@A) already defined in process.obj
SocketSend.obj : error LNK2005: "struct _RTL_CRITICAL_SECTION gCriticalSectionForPrtBuff" (?gCriticalSectionForPrtBuff@@3U_RTL_CRITICAL_SECTION@@A) already defined in process.obj
SocketSend.obj : error LNK2005: "struct probebuff * PtrBuffWrite" (?PtrBuffWrite@@3PAUprobebuff@@A) already defined in process.obj

解决方案 »

  1.   

    你对一个文件进行了多次包含,要避免这种情况,你可以使用条件包含:
    #ifndef xxxx
    #include "xx.h"
    #define xxxx
    #endif
      

  2.   

    我已经加了这个啊,如下:
    #if !defined(MYH)
    #define MYH#include"string"struct  probebuff
    {
    std::string str;
    int len;
    };typedef struct
    {
    char szType[25];
    char ipaddr[12];
    int recpacket;
    int sentpacket;
    int port;
    } SendParam;struct Mail
    {
    unsigned short port;
    char from[100];
    char to[100];
    char subject[100];
    char attachment[100];
    int from_flag;
    int to_flag;
    int subject_flag;
    int attachment_flag;
    int finish;
    struct Mail *next;
    } ;probebuff gProbeBuff1;
    probebuff gProbeBuff2;
    CRITICAL_SECTION gCriticalSectionForBuff;
    CRITICAL_SECTION gCriticalSectionForPrtBuff;
    probebuff * PtrBuffWrite;
    #endif