Agrim Pathak
Agrim Pathak

Reputation: 3207

C++ Header Guards

Suppose I have the following header file:

#ifndef TESTCLASS_H
#define TESTCLASS_H

#include <string>

class TestClass
{
public:
    TestClass();
    std::string test();
};

#endif // TESTCLASS_H

Do I have to put a guard around #include <string> as well? If not, what if main.cpp also has #include <string>?

Upvotes: 1

Views: 86

Answers (2)

Etixpp
Etixpp

Reputation: 328

Not necesarry, the c++ standard libs have their own Guards.

Upvotes: 2

Aasmund Eldhuset
Aasmund Eldhuset

Reputation: 37950

No, because the string header file has got its own include guards (as do the header files of all sensible libraries).

Upvotes: 6

Related Questions