I\'m currently porting my project from Windows to Linux.
The project consists of a \'main\' shared library, several plugins (also shared libraries) and a launcher ap
IMHO the closest thing you can get that suffices your requirements is something using the following pattern:
#include
template
class Singleton {
public:
static Derived& instance() {
static Derived theInstance;
return theInstance;
}
protected:
Singleton() {}
private:
Singleton(const Singleton&);
Singleton& operator=(const Singleton&);
};
class ASingleton : public Singleton {
public:
void foo() { std::cout << "foo() called ..." << std::endl; }
};
int main() {
ASingleton& a = ASingleton::instance();
a.foo();
return 0;
}
Whatever you want to be accessible through an interface might be injected using multiple inheritance. Though the benefit of using a Singleton
base class is a bit questionable, it just provides that narrow instance()
implementation.