如何:显式请求装箱
可以通过将变量显式请求装箱到类型 Object的变量。
示例
// vcmcppv2_explicit_boxing3.cpp
// compile with: /clr
using namespace System;
void f(int i) {
Console::WriteLine("f(int i)");
}
void f(Object ^o) {
Console::WriteLine("f(Object^ o)");
}
int main() {
int i = 5;
Object ^ O = i; // forces i to be boxed
f(i);
f(O);
f( (Object^)i ); // boxes i
}