June 23rd, 2006, 10:26 AM
[RESOLVED] Why ref / value?
Why were the ref / value keywords introduced? I don't see any value they add to the language, they only seem to unnecessary complicate things.
Why can't I inherit a value struct from an other value struct?
June 23rd, 2006, 12:41 PM
Re: Why ref / value?
The CLR has the concept of a reference type and a value-type and we need to expose these concepts in C++/CLI. A reference type lives on the garbage collected heap while a value-type lives on the stack. We did consider (for about 10ms) going the C# route abd having 'struct' mean a value-type but we very quickly decided that this would break too much C++ code.
As value-types are meant to represent small values and as the only live on the stack (if we ignore the thorny issue of boxing) then for performance reasons it makes sense not require that all value-types are sealed. The is a CLR requirment so if C++/CLI wants to run corectly on the CLR we need to follow their rules - and I for one think that this a rule that makes sense. If you find that you need to inherit from a value-type then the changes are that you should really be using a reference-type.
Visual C++ Compiler Team
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!