-
June 23rd, 2006, 10:26 AM
#1
[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?
André
-
June 23rd, 2006, 12:41 PM
#2
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.
Jonathan Caves
Visual C++ Compiler Team
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|