来源:http://www.asawicki.info/Download/Productions/Publications/CPP_CLI_tutorial.pdf
Why Use C++/CLI?
Why learn and use such weird hybrid language if we have C# with nice syntax, designed specifically for .NET platform? C++/CLI has an unique feature among other .NET languages: You can freely mix managed (.NET) and native (C++) code in a single project, single source file, even single function code. It makes the language hard to replace in some applications, like:
- When you write software that needs to use some native as well as managed libraries.
- When you write a library that links native with managed code, for example exposes an interface of somenative library to .NET code.
- When you write a program that needs both efficient processing of some binary data (which is best done in native C++ code using pointers) and has complex graphical interface (which is best one using Windows Forms) – just like I did in my job.
What C++/CLI is Not?
You may think that C++/CLI is some ugly, proprietary hack to C++ introduced by bad “M$” to confuse programmers. That’s not exactly true. Microsoft put effort to make this language really good. Some famous computer scientists and 3 C++ gurus were involved in its development, like Stanley B. Lippman and Herb Sutter. The language itself is standardized as ECMA-372. I must also clarify that C++/CLI is not the same as the old language called Microsoft Extensions for C++. That strange language which extended C++ syntax with ugly keywords like __gc or __value was predecessor of C++/CLI and is now deprecated. The syntax of C++/CLI is totally different and much more pleasant.