Creates a copy of a value class.
__box(value-class-name)
The __box keyword is used to create a managed object (derived from System::Value) from an existing value class. When the __box keyword is applied to a value class:
This process is known as boxing. This enables any value class to be used in generic routines that work for any managed class because the managed class inherits from System::Value, which inherits from System::Object.
Note The newly created managed object is a copy of the value class. Therefore, modifications to the value of the managed object do not affect the contents of the value class.
For more information on boxing and box conversions, see Boxing Conversion and the Value Classes section of Managed Classes.
#using <mscorlib.dll> #using namespace System; __value struct V { int i; }; void Positive(Object*); //expects a managed class void main() { V v={10}; //allocate and initialize Object* o = __box(v); //copy to the NGWS heap Positive( o ); //treat as a managed class o->i = 20; //update the boxed version }
Managed Extensions for C++ Keywords | C++ Keywords