Here are the files responsible for this linker error (Only showing file, namespace and class names):
// PubSub.hpp:
#ifndef PubSub_hpp
#define PubSub_hpp
namespace PubSub {
class Publisher {}
}
}
#endif
// Client.hpp:
#ifndef Client_hpp
#define Client_hpp
#include "PubSub.hpp"
class Client {
}
#endif
// Scene.hpp:
#ifndef Scene_hpp
#define Scene_hpp
#include "Client.hpp"
class Scene {
}
#endif
The code compiles without errors in this state. But as soon as I introduce a variable in PubSub.hpp under the namespace PubSub like below:
// PubSub.hpp:
#ifndef PubSub_hpp
#define PubSub_hpp
namespace PubSub {
class Publisher {}
}
Publisher NetworkEventPublisher("someName");
}
#endif
I get the linker error in the title. I can find a workaround but I am trying to learn C++ so I'm asking what's the rule causing this?