If I want to write my C++ application for multiple platforms, e.g. Windows and Linux, what is the recommended way of writing the platform code? What pattern, class hierarchy etc. exists to accomplish this task? How should I organize my code, header and source files?
I don't get your question completely, but generally you should separate your platform dependent code from platform independent one. for example you may have a folder platform
and inside it a folder for each platform that supported by you, then you may have win32/mutex.hpp
, linux/mutex.hpp
, mac/mutex.hpp
and in each of them you may add implementation of mutex for that platform. Then all you need is a single selector header that based on platform select correct file and include it. For example platform/mutex.hpp
that include any of specified files in correct platform.
But beside that, take a look at boost
it implement many platform dependent code in a platform independent manner, you can learn from it and you may see implementation of your platform dependent code there!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With