With the reference of this Stackoverflow question, I'm not able to figure out the same problem of implementing DI using interface in c++ style, i.e. abstract class. Instead of bumping up old thread I created this one. Compiler throws error for the last line.
class IService {
virtual void DoWork() = 0;
virtual bool IsRunning() = 0;
};
class ClientA : IService {
void DoWork() {
std::cout << "Work in progress inside A";
}
bool IsRunning() {
return true;
}
};
class ClientB : IService {
void DoWork() {
std::cout << "Work in progress inside B";
}
bool IsRunning() {
return true;
}
};
class Server {
IService* _service;
Server(IService* service) : _service(service)
{ }
// Error: this declaration has no storage class or type specifier
// Compiler: MSVC 2017
_service->DoWork();
};