Is there any advantage to using C++/CLI over eithe

2019-01-15 15:44发布

问题:

I'm not seeing any real advantages, other than the fact that you have a C++ syntax, and with it, things like pointers and destructors.

回答1:

If you're talking about why you would use C++/CLI over C#, I think the main reasons are that:

  1. it might be more natural for C++ developers (though I think this is probably not true)
  2. C++/CLI has very nice capabilities for bridging the native and managed environments (using the 'IJW' - It Just Works - technology)

I think that Herb Sutter probably gives the best overview:

A Design Rationale for C++/CLI

If you want to know why you might want to use native C++ over C#/.NET, this boils down to why you would want a managed environment (safety, easier development) over native code (absolute control, possibly speed advantages). There are arguments for each, and the answer really depends on what you want to develop and what your market might be.



回答2:

I think you're referring to C++/CLI and comparing it to C#. C++/CLI isn't a 'flavor' of C++. It's an entirely new language with entirely different standard libraries and entirely different conventions.

At work we find that C++/CLI is valuable as a glue language between C++ and .NET, but we don't use it for anything besides interface glue - C# has enormous advantages over C++ in all other applications.

If you're referring to MS C++ extensions like what Adam describes, there's no reason not to use them if they make your job easier.



回答3:

the really good reason to use C++\CLI is to communicate DotNet language with Native C++, for example many companies migrate first their GUI to .Net and let some logic in C++, and C++\CLI is the good bridge to communicate beteween two techno, you can also use COM components for that, but for many reasons it's not the good choice.



回答4:

I don't think comparing different flavors of C++ to each other is the same question as comparing C++ to C#. C# is a very different beast compared to the differences between different flavors of C++.