C ++包括保护 [英] C++ include guard

查看:146
本文介绍了C ++包括保护的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我知道如何在标准的

So I know how to place an include guard in my own header files with the standard

#ifndef ...
#define ...

现在,我的问题是关于包含不是我自己的库。将是一个很好的例子。我有一个头文件需要使用字符串,所以我做以下

Now, My question is about including libraries that are not my own. would be a good example. I have a header file which requires the use of string, so I do the following

foo.h

#ifndef FOO_H
#define FOO_H

#include <string>

... code etc ...

#endif

现在,如果我有另一个头文件叫..让我们说, bar.h ,它还要求使用 string> ,如何防止多次包含? STL库是否已经包含保护程序?

Now, if I have another header file called.. lets say, bar.h, which ALSO requires the use of <string>, how can i prevent multiple inclusions? Does the STL already have include guards in place?

推荐答案

#ifndef _GLIBCXX_STRING
#define _GLIBCXX_STRING 1

这来自gcc的

这篇关于C ++包括保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆