spi*_*ing 2 c++ include c-preprocessor
获取LNK2005"已在GUI.obj中定义"以获取PAL.h中的函数指针
//GUI.cpp
#include "PAL.h"
//PAL.h
#define PAL_INCLUDE
int (*addPAL)( int, void(*)(), void(*)() );
//main.cpp
#include "GUI.h"
#ifndef PAL_INCLUDE
#include "PAL.h"
#endif
Run Code Online (Sandbox Code Playgroud)
我误解了包含的本质#ifndef
吗?
您可能是因为预处理器在GUI.cpp之前处理main.cpp而得到错误.尝试将您的内容更改为PAL.h
:
#ifndef PAL_INCLUDED
#define PAL_INCLUDED
// definitions
#endif
Run Code Online (Sandbox Code Playgroud)
参考