[英]Why there set macro definition and namespace in C++ .h file?
I am reading this open source project :我正在阅读这个开源项目:
I have two questions:我有两个问题:
#ifndef _RANGE_REQUEST_GENERATOR_H_
#define _RANGE_REQUEST_GENERATOR_H_
#endif
and I only find the _RANGE_REQUEST_GENERATOR_H_
in this .h file, other place not use it.我只在这个 .h 文件中找到了
_RANGE_REQUEST_GENERATOR_H_
,其他地方不使用它。
so, what's the usage of the macro definition?那么,宏定义的用途是什么?
namespace slowhttptest {
//functions
}
what's the purpose?目的是什么? why do not use
std
, is it better?为什么不使用
std
,是不是更好?
See Purpose of Header guards见标题守卫的目的
Consider the case where you are using libraries.考虑使用库的情况。 And two libraries would both like to have a function named
Push()
.两个库都希望有一个名为
Push()
的函数。 We could name them: LibraryFoo_Push()
, and LibraryBar_Push()
, or we could use namespaces.我们可以将它们命名为:
LibraryFoo_Push()
和LibraryBar_Push()
,或者我们可以使用命名空间。 Namespaces have some additional benefits with lookups as well.命名空间在查找方面也有一些额外的好处。
And see C++ When is it OK to extend the `std` namespace?并参见C++ 何时可以扩展 `std` 命名空间? for when you are allowed to add stuff to the
std
namespace.当您被允许向
std
命名空间添加内容时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.