C++收割台防护装置

C++ Header Guards

本文关键字:装置 收割 C++      更新时间:2023-10-16

假设我有以下头文件:

#ifndef TESTCLASS_H
#define TESTCLASS_H
#include <string>
class TestClass
{
public:
    TestClass();
    std::string test();
};
#endif // TESTCLASS_H

我是否也必须在#include <string>周围设置警卫?如果没有,如果main.cpp也有#include <string>怎么办?

否,因为string头文件有自己的包含保护(所有合理库的头文件也是如此)。

没有必要,c++标准库有自己的Guard。