[RESOLVED] Why ref / value?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: [RESOLVED] Why ref / value?

  1. #1
    Join Date
    Dec 2005
    Posts
    16

    [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é
    Share on Google+

  2. #2
    Join Date
    May 2006
    Posts
    22

    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
    Share on Google+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center