Questions on __value class

  • Thread starter Thread starter Simon Cheng
  • Start date Start date
S

Simon Cheng

Hi,

In C#, value types are derived from System.ValueType (and hence from
System.Object).

Does this hold true for MC++?

__value class ValueClass {...};

Is ValueClass above derived from System::ValueType (and hence from
System::Object)?

Thanks,
Simon
 
Thanks, Jochen. The next question:

The derivation chain for ValueClass is:

System::Object
System::ValueType
ValueClass

Why objects derived from System::ValueType (_indirectly_ from
System::Object) are always allocated on stack, whereas objects derived
_directly_ from System::Object are always allocated on CLR heap? This means
if a value object calls a method inherited from System::Object but doesn't
override it, then the object needs to be boxed before the call can be made.
Is this just how it is designed?

Simon
 
Simon said:
The derivation chain for ValueClass is:

System::Object
System::ValueType
ValueClass

Why objects derived from System::ValueType (_indirectly_ from
System::Object) are always allocated on stack, whereas objects derived
_directly_ from System::Object are always allocated on CLR heap? This means
if a value object calls a method inherited from System::Object but doesn't
override it, then the object needs to be boxed before the call can be made.
Is this just how it is designed?

That's pretty accurate. Here are a couple of articles that give some
background on value types:

CLR Design Choices
A Conversation with Anders Hejlsberg, Part VIII
Value Types
http://www.artima.com/intv/choices3.html

Value Types
http://blogs.msdn.com/cbrumme/archive/2003/05/10/51425.aspx
 
Back
Top