C++ Constructor Inheritance (Invoking Constructor from Derived Class) -


I inherited a base class constructor / I left a boost class. Asoo example

Here is the parent class:

  #ifndef CLIENT_HPP # define CLIENT_HPP #include & lt; Iostream & gt; #include & lt; Memory & gt; # Include & lt; Utility & gt; # Include & lt; Boost / asio.hpp & gt; # Include & lt; Boost / lexical_cast.hpp & gt; Boost :: asio :: ip :: tcp is using; Class Client: Public std :: enable_shared_from_this & lt; Client & gt; {Public: Client (TCP :: socket socket): socket_ (std :: move socket) {} zero start () {} tcp :: socket socket_; }; #endif   

Here is the child class:

  #ifndefpenguin_hpp #define penguin_hpp #include "Client.hpp" class Penguins: Public Customers {Public: Penguins (): Customers (Socket_) {}}; In this way I use  Penguin  class  
  std :: make_shared & lt; Penguins & gt; (Std:: this step (socket_)) - & gt; Start (); Here is the  TCP :: socket  of the server   

socket _ .

I am a C + + Nob, so any help will be greatly appreciated!

First of all, we clarify. In C ++, the consultants are not inherited from the behavior of the constructors in a class hierarchy, it seems that the constructor is inherited, and some argue that I am a lot of pundit, but I It seems important to understand this distinction.

The question now is how do you tell the creator of the base category of your derived class producer? The answer is within the derived category 'Constructor Initialization List - As You Are.

However there is a problem in how you are actually going about it

  Penguin (): Customer (socket_) {}   

Here, socket _ is a member of the base class, the customer (unless someone typos in your post.) socket _ The object being referred ago client has been given immediately, so it still does not exist. It is a chicken-egg problem to install customer , you need socket _ , but socket_ for reference, you < Code> customer , and green goes ...

Not a short part of my advice which I can ask you to fix this problem, because Unfortunately, there is no easy decision. The real problem here is that your design is broken. It is broken due to cyclical dependency that you present between the base class and the members of that base class. You have to see your design again.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -