How to: Use gcnew to Create Value Types and Use Implicit Boxing
Using gcnew on a value type will create a boxed value type, which can then be placed on the managed, garbage-collected heap.
Example
// vcmcppv2_explicit_boxing4.cpp
// compile with: /clr
public value class V {
public:
int m_i;
V(int i) : m_i(i) {}
};
public ref struct TC {
void do_test(V^ v) {
if (v != nullptr)
;
else
;
}
};
int main() {
V^ v = gcnew V(42);
TC^ tc = gcnew TC;
tc->do_test(v);
}
See also
Phản hồi
https://aka.ms/ContentUserFeedback.
Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem:Gửi và xem ý kiến phản hồi dành cho