[英]How to declare a C++ variable type based on platform?
I'm trying to write some C++ code that will work on both Windows and Linux.我正在尝试编写一些适用于 Windows 和 Linux 的 C++ 代码。 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;
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):或者,如果您更喜欢
using
(尽管在这种情况下没有区别):
#ifdef WINDOWS
using TYPE = HINSTANCE;
#else
using TYPE = void*;
#endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.