C++ has namespaces to prevent collisions of things with the same name.
Header guards serve a different purpose. They prevent include
ing the same header twice. However, they can suffer from the same problem: what if two header guards from different files use the same popular name? What if there are two libraries that have a LinkedList
class:
#ifndef LinkedList_H
#define LinkedList_H
// stuff
#endif
Why are those two means to uniquely identify code so different?
It's like one sophisticated language feature on one side and some macro contraption with an arbitrary string on the other.
Why are naming conflicts not a problem for header guards? Shouldn't the namespace be part of the header guard, to make it as unique as the namespace, so that it not only prevents duplicated include
but also naming conflicts?
#pragma once
.