In VC++ 2013, you can have a boxed object as a member of a value type. Example code below.
value class Member sealed
{
public:
String^ name;
IBox<int>^ age;
};
Here’s some code showing how the type can be used.
Member member; member.name = "Nish"; member.age = 80; int age = member.age->Value; member.age = nullptr;
Even in normal boxing/unboxing, when you use a safe_cast on a boxed object, eventually what happens is that a safe_cast to IBox<T> is performed and then the Value property accessed. Example, the following two snippets are semantically identical.
int y = 11; // snippet 1 Object^ obj = y; int y3 = safe_cast<int>(obj); // snippet 2 IBox<int>^ boxedY = safe_cast<IBox<int>^>(obj); int y2 = boxedY->Value;