Beta problems... 'this' pointer in union?
    Andrej Mitrovic 
    andrej.mitrovich at gmail.com
       
    Tue Jan  1 07:25:49 PST 2013
    
    
  
On 12/30/12, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> Looking at the code though, I'm shocked to see a function declaration in a
> union. I wouldn't have thought that that was legal.
It's legal in C++ and in D. I find it useful when interfacing with C++
non-POD types which have an embedded union, because it allows me to
group related properties under a union declaration (it serves only as
documentation), for example:
C++:
class Foo
{
public:
    Foo() { }
    union
    {
        int var1;
        bool var2;
    };
};
D:
///
class FooWrapper
{
    /// union property
    union
    {
        @property int var1();
        @property void var1(int i);
        @property bool var2();
        @property void var2(bool i);
    }
}
    
    
More information about the Digitalmars-d-learn
mailing list