动机:
我想开启VC++的内存检测功能,要求某些语句必须在最前面,如下:
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
问题:
假设我有一个头文件forefront.h
,我想要的是如下效果:
a.cpp
#include <any_other_one.h>
#include <forefront.h> // An compiler error generated here!
b.cpp
#include <forefront.h> // OK
#include <any_other_one.h>
如何实现?
最佳答案
使用以下内容创建您自己的头文件:
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
现在使用项目设置的“高级”部分中的“强制包含”设置。此处指定的任何文件都将按照指定的顺序包含在所有其他文件之前。
关于c++ - 如何在最前面执行一个头文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18971801/