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: Here is the child class: 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 Here, 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.
#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
#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
Penguin (): Customer (socket_) {}
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 ...
Comments
Post a Comment