sockpp icon indicating copy to clipboard operation
sockpp copied to clipboard

Making to_string as a virtual function accessible from sock_address class

Open arsdever opened this issue 5 years ago • 2 comments

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.

arsdever avatar May 23 '20 17:05 arsdever

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.

fpagliughi avatar May 27 '20 13:05 fpagliughi

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?

arsdever avatar May 27 '20 18:05 arsdever