Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-Platform C++ code and single header - multiple implementations

Tags:

People also ask

Can you have multiple classes in one header file?

Keep one class per file with the corresponding header in a separate file. If you do otherwise, like keeping a piece of functionality per file, then you have to create all kinds of rules about what constitutes a piece of functionality. There is much more to gain by keeping one class per file.

Is C++ good for cross-platform?

C++ is best suited for developing software like operating systems, database engines, game engines, compilers, and servers. At the same time, C++ is a great choice as a cross-platform language.

What is a cross-platform C++?

It installs the SDKs and tools you need for cross-platform development of shared libraries and native apps. When it's installed, you can use C++ to create code that runs on iOS and Android devices and platforms, Windows, Windows Store, and Xbox.


I have heard that a way to write Cross Platform c++ code is to define classes as follows (for example, a Window class):

window.h window_win32.cpp window_linux.cpp window_osx.cpp 

and then choose the implementation file accordingly. But what if i have members of that class that are relative to the os? Like a HWND member for the Win32 implementation. I can't put it in the window.h or when i'd try to compile it on, say, Linux, it'd generate a compiler error.

Do i need to #ifdef it? I've already asked a similar question but this one is more focused on this particular problem.