The second question is: When do I use what of these two?

- 30,738
- 21
- 105
- 131

- 773
- 1
- 9
- 15
-
1Managed Extensions for C++ or just Managed C++ is a now deprecated Microsoft set of deviations from C++, including grammatical and syntactic extensions, keywords and attributes, to bring the C++ syntax and language to the .NET Framework. These extensions allowed C++ code to be targeted to the Common Language Runtime (CLR) in the form of managed code as well as continue to interoperate with native code. Managed C++ was not a complete standalone, or full-fledged programming language. https://en.wikipedia.org/wiki/Managed_Extensions_for_C%2B%2B#.E2.80.A6to_C.23 – NoWar Nov 13 '15 at 17:33
-
I think you should look at [this question](https://stackoverflow.com/questions/57923/what-exactly-is-managed-code). – GSerg Sep 22 '08 at 11:04
5 Answers
When not specified, C++ is unmanaged C++, compiled to machine code. In unmanaged C++ you must manage memory allocation manually.
Managed C++ is a language invented by Microsoft, that compiles to bytecode run by the .NET Framework. It uses mostly the same syntax as C++ (hence the name) but is compiled in the same way as C# or VB.NET; basically only the syntax changes, e.g. using '->' to point to a member of an object (instead of '.' in C#), using '::' for namespaces, etc.
Managed C++ was made to ease transition from classic C++ to the .NET Framework. It is not intended to be used to start new projects (C# is preferred).

- 5,953
- 14
- 43
- 59
-
1A caution on the advice to not use managed c++ for new projects. From Visual Studio 2008 onwards Managed c++ has some features that are superior to c#. These relate to the handling of IDisposable objects. See http://msdn.microsoft.com/en-us/library/ms235315.aspx – morechilli Sep 22 '08 at 13:19
-
24Managed C++ and C++/CLI are two different beasts. Managed C++ is a hideous extension to C++ that should never have seen the light of day. C++/CLI is officially a separate language, so new keywords can be added, and is much nicer to work with. – Eclipse Sep 22 '08 at 17:03
-
-
2
-
1Contrary to popular belief, Managed C++ doesn't compile to bytecode, but a mixed mode executable switching between bytecode and native code, depending on what objects are being used. It is possible to create a purely managed executable using C++/CLI if none of "unsafe" C++ features (like none of CRT or STL) are used. – rustyx Jan 22 '19 at 20:45
"Managed C++" refers to a language that was included in Visual Studio.NET/Visual Studio.NET 2003. It has since been deprecated, with the latest .NET C++ being C++/CLI.

- 30,738
- 21
- 105
- 131

- 10,742
- 12
- 54
- 74
You can code native C++ two different ways. The first is compiling directly to machine code with just the operating system between you and the platform (hardware). The second native coding is done with MFC (Microsoft Foundation Classes). This is the same as the first example except for the use of MFC.
Managed C++ uses the CLR (Common Language Runtime). The CLR along with the .NET framework class libraries make up the .NET Framework. This managed C++/CLI standard uses the .NET framework along with the CIL (Microsoft Intermediate Language). This standard works by mapping to machine code only when the program is executing by the use of a just in time compiler. If your code will be running on different hardware platforms the use of managed code will be much easier. As with all thing there is a slight price to pay for convenience, as native code will run faster.

- 30,738
- 21
- 105
- 131
You'll be using managed C++ when want to use a native C++ class library from managed code. In this case you wrap unmanaged classes in managed C++ ones, then you use them in any CLR language.

- 147
- 1
- 4
Managed C++ means that memory allocation, management, garbage collection is handled by the virtual machine. Whereas in "regular" C++ you would have to allocate and deallocate memory.

- 4,089
- 2
- 27
- 30