C++/CLI article in MSDN
There is certainly a lot more to be said about C++/CLI, never mind the Visual C++ 2005 compiler, but I hope this article has provided you with a good introduction to what it has to offer for programmers targeting the CLR. The new language design provides unprecedented power and elegance to write rich .NET applications completely in C++ without sacrificing productivity, conciseness, or performance.
The following table provides a summary of the most common constructs for quick reference.
Description | C++/CLI | C# |
---|---|---|
Allocate reference type | ReferenceType^ h = gcnew ReferenceType; | ReferenceType h = new ReferenceType(); |
Allocate value type | ValueType v(3, 4); | ValueType v = new ValueType(3, 4); |
Reference type, stack semantics | ReferenceType h; | N/A |
Calling Dispose method | ReferenceType^ h = gcnew ReferenceType;
delete h; |
ReferenceType h = new ReferenceType();
((IDisposable)h).Dispose(); |
Implementing Dispose method | ~TypeName() {} | void IDisposable.Dispose() {} |
Implementing Finalize method | !TypeName() {} | ~TypeName() {} |
Boxing | int^ h = 123; | object h = 123; |
Unboxing | int^ hi = 123;
int c = *hi; |
object h = 123;
int i = (int) h; |
Reference type definition | ref class ReferenceType {};
ref struct ReferenceType {}; |
class ReferenceType {} |
Value type definition | value class ValueType {};
value struct ValueType {}; |
struct ValueType {} |
Using properties | h.Prop = 123;
int v = h.Prop; |
h.Prop = 123;
int v = h.Prop; |
Property definition | property String^ Name { String^ get() { return m_value; } void set(String^ value) { m_value = value; } } |
string Name { get { return m_name; } set { m_name = value; } } |
About the author
Kenny Kerr spends most of his time designing and building distributed applications for the Microsoft Windows platform. He also has a particular passion for C++ and security programming. Reach Kenny at http://weblogs.asp.net/kennykerr/ or visit his Web site: http://www.kennyandkarin.com/Kenny/.
[출처] C++/CLI article in MSDN|작성자 MON
'Programming > C++/CLI' 카테고리의 다른 글
[Step 02-1] 클래스(class), 핸들(^), 그리고 구조체(struct) (0) | 2010.10.05 |
---|---|
C + + 프로그래머를위한 C + + / CLI 소개 (0) | 2010.10.05 |
C++ Interop 사용(암시적 PInvoke) (0) | 2010.09.14 |
C++/CLI에 대해서 알아두어야 할 것들 (0) | 2010.09.13 |
C++/CLI Type (2) | 2010.09.13 |