Results 1 to 2 of 2
Hi all,
I have a basic question, I have code that is written for linux (has unix specific calls that are not included in windows api) and I need to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 08-10-2011 #1Just Joined!
- Join Date
- Aug 2011
- Posts
- 1
C++ code in Linux and windows
Hi all,
I have a basic question, I have code that is written for linux (has unix specific calls that are not included in windows api) and I need to port it to windows. It must remain backwards compatible with unix environment though.
What is the best way to achieve this? Currently, I've been going through adding
Is this the best way? The project has about 8 or 9 objects being used, so it is fairly small in size, and the basic operations are file I/O with timestamps.Code:#ifndef WIN32 // perform unix-specific calls #else // perform windows specific calls #endif
Thank you all.
- 08-11-2011 #2
You have lots of options, how about encapsulating the different calls into two derived classes providing the service? Sort of like...
Store your instance in a pointer to the parent class, but instantiate the one that matches the system you're compiling for. You don't even need to include the class that handles the 'other' platform in each of your builds.Code:class service { public: do_something(); // which calls system_call_x() below to do 'systemsy' stuff protected: virtual system_call_x(); } class service_w : public service { protected: virtual system_call_x(); } class service_l : public service { protected: virtual system_call_x(); }Linux user #126863 - see http://linuxcounter.net/


Reply With Quote
