如何便携的是C ++? [英] How portable IS C++?

查看:104
本文介绍了如何便携的是C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中,如果我使用Linux编写一个像pong这样的简单游戏,那么同样的代码可以在Windows和OSX上编译吗?

In C++, if I write a simple game like pong using Linux, can that same code be compiled on Windows and OSX? Where can I tell it won't be able to be compiled?

推荐答案

C ++是超便携的,并且编译器可在更多平台上使用比你可以摇一根棍子。像Java这样的语言通常被称为大规模跨平台,讽刺的是,它们实际上通常用C ++或C来实现。

C++ is ultra portable and has compilers available on more platforms than you can shake a stick at. Languages like Java are typically touted as being massively cross platform, ironically they are in fact usually implemented in C++, or C.

涵盖可移植性。如果你实际上意味着,如何跨平台是C + +,那么不是那么多:C ++标准只定义了一个适合于控制台IO的IO库 - 即基于文本,所以一旦你想开发某种GUI,你会需要使用GUI框架 - 和GUI框架历史上非常平台特定。 Windows现在有多个本地的GUI框架 - 从Microsoft提供的C ++框架仍然是MFC - 它包装本机Win32 API,这是一个C API。 (WPF和WinForms可用于CLR C ++)。

That covers "portability". If you actually mean, how cross platform is C++, then not so much: The C++ standard only defines an IO library suitable for console IO - i.e. text based, so as soon as you want develop some kind of GUI, you are going to need to use a GUI framework - and GUI frameworks are historically very platform specific. Windows has multiple "native" GUI frameworks now - the C++ framework made available from Microsoft is still MFC - which wraps the native Win32 API which is a C API. (WPF and WinForms are available to CLR C++).

Apple Mac的GUI框架称为Cocoa,是一个目标C库,但它易于访问Objective C

The Apple Mac's GUI framework is called Cocoa, and is an objective-C library, but its easy to access Objective C from C++ in that development environment.

在Linux上有GTK +和Qt框架,它们实际上都移植到Windows和Apple,所以其中一个C ++框架可以解决你的如何在C ++中编写一个GUI应用程序,一旦在Windows,苹果mac和linux上构建和运行。

On Linux there is the GTK+ and Qt frameworks that are both actually ported to Windows and Apple, so one of these C++ frameworks can solve your "how to write a GUI application in C++ once that builds and runs on windows, apple mac and linux".

当然,它很难将Qt视为严格的C ++ - Qt定义了需要预编译编译步骤的信号和槽的特殊标记。

Of course, its difficult to regard Qt as strictly C++ anymore - Qt defines a special markup for signals and slots that requires a pre-compile compile step.

这篇关于如何便携的是C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆