fpagliughi / sockpp

Modern C++ socket library.
BSD 3-Clause "New" or "Revised" License
782 stars 126 forks source link

Making to_string as a virtual function accessible from sock_address class #48

Open arsdever opened 4 years ago

arsdever commented 4 years ago

Based on my observation and my usage, sometimes it is useful to get the string representation of the IP address of the socket. But in case you have a simple sock_address type object, you must do some additional actions (checking the type and casting) to have your job done correctly. For this purpose, I moved the to_string function up to sock_address class and made it virtual.

fpagliughi commented 4 years ago

This seems like a good idea. But I would think to make it purely virtual function in the base class:

virtual std::string to_string() const =0;

That would force the child classes to output something useful.

But note that this, especially, would be a breaking change in the API. It could break someone's build if they used the sock_address class for an additional socket type in the library/application.

arsdever commented 4 years ago

But note that this, especially, would be a breaking change in the API. It could break someone's build if they used the sock_address class for an additional socket type in the library/application.

That is why I specified default implementation. Maybe merging this to future branch with pure virtual implementation?