To follow from my previous question about virtual and multiple inheritance (in a cross platform scenario) - after reading some answers, it has occurred to me that I could simplify my model by keeping the server and client classes, and replacing the platform specific classes with #ifdefs (which is what I was going to do originally).
Will using this code be simpler? It'd mean there'd be less files at least! The downside is that it creates a somewhat "ugly" and slightly harder to read Foobar
class since there's #ifdefs
all over the place. Note that our Unix Foobar source code will never be passed to the compiler, so this has the same effect as #ifdef
(since we'd also use #ifdef
to decide what platform specific class to call).
class Foobar {
public:
int someData;
#if WINDOWS
void someWinFunc1();
void someWinFunc2();
#elif UNIX
void someUnixFunc1();
void someUnixFunc2();
#endif
void crossPlatformFunc();
};
class FoobarClient : public Foobar;
class FoobarServer : public Foobar;
Note: Some stuff (ctor, etc) left out for a simpler example.
Update:
For those who want to read more into the background of this issue, I really suggest skimming over the appropriate mailing list thread. Thing start to get interesting around the 3rd post. Also there is a related code commit with which you can see the real life code in question here.
class FuncsWin32 : public Foobar
andclass FuncsUnix : public Foobar
. This allows the builder to include the appropriate widgets without the rest of the program caring. – Quimby