CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2005

    [RESOLVED] Managed unions?

    value struct myStruct
    int myInt;

    union myUnion
    myStruct iShareMyMemory;
    myStruct meToo;

    Results in the error C2848: 'myUnion::iShareMyMemory' : a managed type cannot be a member of a union.

    StructLayout also doesn't seem to work.

    Will this be supported with the next release?

  2. #2
    Join Date
    May 2006

    Re: Managed unions?

    There are supported today - though it is ugly:

    using namespace System;
    using namespace System::Runtime::InteropServices;

    [ StructLayout(LayoutKind::Explicit) ]
    public value struct MyUnion
    [ FieldOffset(0) ]
    int data1;

    [ FieldOffset(0) ]
    String^ data2;

    [ FieldOffset(0) ]
    Double data3;

    We have no current plans to 'improve' this support.
    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

Click Here to Expand Forum to Full Width