Better have Windows and Linux implementations in separate files and in separate classes. Common methods can be virtual. Additionally a socket can be opened in constructor and closed in a destructor for basic RAII. Host and port can be passed as an arg.
A better alternative to having #ifdef is if constexpr (isWindowsPlatform()).
Even though the cost of the virtual call would be totally optimised away by a compiler, sure it does not have to be virtual. Still would at least place platform-specific implementations into different translation units.
2
u/MiaowMeoow Nov 19 '23
Better have Windows and Linux implementations in separate files and in separate classes. Common methods can be virtual. Additionally a socket can be opened in constructor and closed in a destructor for basic RAII. Host and port can be passed as an arg.
A better alternative to having #ifdef is if constexpr (isWindowsPlatform()).
Good video !