This time we'll exercise templates and the
typeid keyword to build a
Guice-inspired dependency injection framework. Write class
Injector that allows you to write
class IService {
public:
virtual ~IService() {};
virtual void serve() = 0;
};
class HelloService : public IService {
public:
void serve() {
std::cout << "Hello, world!" << std::endl;
}
};
int main() {
Injector injector;
injector.bind<IService>().to<HelloService>();
IService* service = injector.newInstance<IService>();
service->serve();
delete service;
return 0;
}
Ei kommentteja:
Lähetä kommentti