Declares a class to be a value class.
__value class-specifier __value struct-specifier
Value classes differ from managed classes in that value class variables directly contain their data, whereas managed variables point to their data, which is stored on the heap.
The following restrictions apply only to value classes:
A value class can be explicitly connected to a System::Object pointer. This is known as boxing. For more information, see Value Classes in Managed Extensions for C++.
Note The __value keyword is illegal when used with the __abstract keyword.
In the following example, a value class is declared (V
) and then two instances of the value class are manipulated:
#using <mscorlib.dll> #using namespace System; __value struct V { int m_i; }; void main() { V v1, v2; v1.m_i = 5; v2 = v1; // copies all fields of of v1 to v2 v2.m_i = 6; // does not affect v1.m_i }
Managed Extensions for C++ Keywords | C++ Keywords