1

I wrote a managed C++ application a few years ago. It was just a personal project and I chose managed c++ just because I found it interesting. I remember it felt like it just took a lot more time than doing c# and there wasn't anything to gain from it in my case at least.

When is C++/CLI a good choice in reality? What is it's benefits?

Carl R
  • 8,104
  • 5
  • 48
  • 80
  • Also, this is a duplicate of http://stackoverflow.com/questions/1933210/c-cli-why-should-i-use-it, which gave a better answer than I did – Patrick Lafferty Oct 04 '11 at 18:17
  • This is a closer dupe: http://stackoverflow.com/questions/1874783/what-are-the-situations-or-pros-and-cons-to-use-of-c-cli-over-c – Ben Voigt Oct 05 '11 at 14:23
  • and http://stackoverflow.com/questions/1886881/c-cli-advantages-over-c and http://stackoverflow.com/questions/297323/is-there-any-advantage-to-using-c-cli-over-either-standard-c-or-c – Ben Voigt Oct 05 '11 at 14:24

2 Answers2

3

The only reason for using C++/CLI is so you can use a native library in a managed application. Even Microsoft says it shouldn't be used on its own:

The second major consideration for using C++/CLI is to remember that this is only intended to be a bridge between the managed and native worlds and not intended to be a technology you use to write the bulk of your application. It is certainly possible to do so, but you'll find that developer productivity is much lower than in a pure C++ or pure C#/Visual Basic environment and that your application runs much slower to boot. So when you use C++/CLI, compile only the files you need with the /clr switch, and use a combination of pure managed or pure native assemblies to build the core functionality of your application.

http://msdn.microsoft.com/en-us/magazine/dd315414.aspx#id0070020

Patrick Lafferty
  • 571
  • 3
  • 12
3

For me, it's far less difficult to write managed code in C#, but sometimes the performance that C++ offers makes it a better choice. I write the performance-critical code in c++, and the rest in C#. The only reason for C++/CLI is so that the native code and managed code can be used together.

Herb Sutter's design rational:

C++/CLI’s mission is to provide direct access for C++ programmers to use existing CLI libraries and create new ones, with little or no performance overhead, with the minimum amount of extra notation, and with full ISO C++ compatibility.

http://www.gotw.ca/publications/C++CLIRationale.pdf

Meta
  • 121
  • 6