1. Why need it?
Mainly it works as the bridge between managed code and native C ++ code, as it's the only graceful way to be able to talk to both sides.
Using/CLI compiler option, it can generate mixed code to benefit below cases:
1. I believe most companies have some old c ++ code. In the era of C ++, we have invested a lot in C ++ and may have produced many stable products. In today's surging. Net tide, do we need to rewrite this code? Of course, there is no need to know the legacy code. It does not mean that the code is faulty. On the contrary, most of such code is a mature product and has undergone many tests. If you rewrite the statement, you will introduce a lot of bugs and re-test the bug. It can be said that it is a thankless effort.
2. the emergence of DOTNET will not bring C ++ into the desperate situation. In some scenarios that require speed, such as Algorithm Implementation, pattern recognition, and drivers, C ++ is required. Any language is not perfect. Although we are all pursuing perfection, perfection does not exist. Therefore, we also need to make some trade-offs.
3. Sometimes we only need c ++ interfaces for third-party software. We do not have source code, so we do not have the possibility to rewrite the code. But we can write a wrapper through C ++/CLI for. net.
4. Sometimes some sensitive algorithms are implemented with unmanaged code for code security considerations. After all, managed code is easily decompiled.
2. Basic syntax
1. Ref/value
Ref/value class/struct: Reference Type + value type.
2. Boxing/unboxing
(Example)
Int I = 123;
Int ^ HI = I;
Int c = * Hi;
Hi = nullptr;
3. New keywords
Gcnew: allocate reference type object onto managed heap.
Type ^: declare a handle that just like CSHARP reference and C ++ native pointer.
Reference: http://msdn.microsoft.com/en-us/library/ms379617 (vs.80). aspx