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?
Share
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
platformand inside it a folder for each platform that supported by you, then you may havewin32/mutex.hpp,linux/mutex.hpp,mac/mutex.hppand 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 exampleplatform/mutex.hppthat include any of specified files in correct platform.But beside that, take a look at
boostit 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!!