0

I have 2 classes Main-Server and Sub-Server ,The main-server class has a sub-server vector as a memmber.in addition I want that the sub server will inherited methods (void run()) from the main-server class, but I got the error "forward declaration of 'struct cMain_server " . Could you help me please what I am doing wrong? Forward declaration doesn't work for me..

hpp:

class cMain_server;
class cSub_server : public cMain_server {
 public:
  // Constructor
  cSub_server();

 private:
};
class cMain_server {
 public:
  // Constructor
  cMain_server();
  void run();

 private:
  vector<cSub_server> mSub_server_vec;
};
Aykhan Hagverdili
  • 28,141
  • 6
  • 41
  • 93
Elior
  • 41
  • 5
  • 1
    I think you should switch the order. Declare the sub-server in the first line, then define the main server and finally define the sub server. – SomethingSomething Apr 25 '21 at 13:32
  • 1
    @SomethingSomething Unfortunately that won't help, unless the vector is changes to something like `std::vector> mSub_server_vec;` – πάντα ῥεῖ Apr 25 '21 at 13:37
  • You can make this work through use of pointers and a lot of sweat, blood & tears, but it seems like just bad design. – Aykhan Hagverdili Apr 25 '21 at 13:46
  • @Elior As already mentioned, I also believe, that this is a serious design flaw: A _SubServer_ cannot be a _MainServer_ at the same time, that's contradictorily. They may have a common base class, and a _MainServer_ may have a collection of _SubServers_, but a _SubServer_ never _**is a**_ _MainServer_. I'd recommend you to think that over again. – πάντα ῥεῖ Apr 25 '21 at 13:51
  • Thank you all , I will think again about the design :) – Elior Apr 25 '21 at 13:57

0 Answers0