我看到一个项目中的.h 文件,内容如下:
#ifndef _RANGE_REQUEST_GENERATOR_H_
#define _RANGE_REQUEST_GENERATOR_H_
#include <string>
namespace httptest {
void GenerateHeadRequestWithRange(const std::string& verb,
const std::string& path, const std::string& host,
int start, int step, int limit,
std::string* output);
} // namespace
#endif // _RANGE_REQUEST_GENERATOR_H_
我有几个问题:
1)宏定义_RANGE_REQUEST_GENERATOR_H_ 这个有何作用?我在整个项目中也只看到这个.h文件才有_RANGE_REQUEST_GENERATOR_H_,其他文件没有使用到:
#ifndef _RANGE_REQUEST_GENERATOR_H_
#define _RANGE_REQUEST_GENERATOR_H_
#endif
2)为何需要在方法定义外添加namespace包裹?为何不使用std命名空间呢,它有什么好处?
namespace httptest {
方法
}
3)这里的std::string
指的是标准命名空间下的string模块吗?与现在的httptest命名空间区别开来,是这个意思吗?
sort
函数时就不能用std
,因为已被用掉了。当然你可以不放在命名空间中,但这样用你的库的人就不能定义
sort
了。std::string
指的是std
中的string
类。当然命名空间中不一定是类。