__box: 找不到标识符

__box: identifier not found

我认为“__box”:标识符在 VS 2015 编译器中已弃用。有什么替代方案?

#using <mscorlib.dll>
using namespace System;
using System::Collections::Stack;

int main() {
   Stack* pS = new Stack();
   Int32 i = 5;       
   pS->Push( __box(i) );
}

MSDN about _box

现在有implicit boxing

The Visual C++ compiler now boxes value types to Object. This is possible because of a compiler-defined conversion to convert value types to Object. Boxing and unboxing enable value types to be treated as objects. Value types, including both struct types and built-in types such as int, can be converted to and from the type Object. Compiler option: /clr

来自 here 的代码:

// clr_implicit_boxing_Std_conversion.cpp
// compile with: /clr
int f3(int ^ i) {   // requires boxing
   return 1;
}

int f3(char c) {   // no boxing required, standard conversion
   return 2;
}

int main() {
   int i = 5;
   System::Console::WriteLine(f3(i));
}

在 Visual Studio 2015 中删除了对 /clr:oldsyntax 的支持(旧语法自 Visual Studio 2005 以来已被弃用)。参见 "Compiler Switch Deprecation/Removal Changes in Visual Studio '14'."

旧语法托管 C++ 源代码必须移植到 C++/CLI。例如,

Stack^ pS = gcnew Stack();
Int32 i = 5;
pS->Push(i);