我有 2 个头文件,我在其中定义了特殊的结构。这些结构名称是相同的。当我同时调用 main.cpp 时,出现“以前的定义在这里”错误。我怎样才能避免这个错误?
例子:
#include "New1H.h"
#ifndef New1H #define New1H
enum TState
{
A = -1,
B= 0,
C
};
#endif
#include "New2H.h"
#ifndef New2H #define New2H
enum TState
{
A = -1,
B= 0,
C
};
#endif
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "New1H.h"
#include "New2H.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
错误代码:
[bcc32c 错误] New2H.h(57): 'TState' 的重新定义 New1H.h(71):之前的定义在这里
我尝试了网站上的解决方案但失败了。