How to declare a C++ variable type based on platform?

Viewed 109

I'm trying to write some C++ code that will work on both Windows and Linux. I currently have this:

#ifdef WINDOWS
  HINSTANCE _handle;
#else
  void* _handle;
#endif

Is it possible to declare the type to be conditional based on the platform instead so that i could do something like:

#ifdef WINDOWS
  //define TYPE = HINSTANCE;
#else
  //define TYPE = void*;
#endif
TYPE _handle;
1 Answers

Do you mean something like:

#ifdef WINDOWS
  typedef HINSTANCE TYPE;
#else
  typedef void* TYPE;
#endif

TYPE _handle;

Or, if you prefer using (altough in this context there is no difference):

#ifdef WINDOWS
  using TYPE = HINSTANCE;
#else
  using TYPE = void*;
#endif
Related