Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

value struct not initialized in WinRT

For whatever reason, the initialized value of a value struct defined in Windows Runtime Component is ignored in the app (C#).

CX/C++:

namespace RuntimeComponent1
{
    public value struct Foo {
        bool flag1 = true;
        bool flag2 = false;
    };
}

C#

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();

        var settings = new RuntimeComponent1.Foo();
        Debug.WriteLine(settings.flag1); // Output: False
        Debug.WriteLine(settings.flag2); // Output: False
    }
}

Notice that flag1 should be True but instead it is False. Why? !


Edit: As suggested by @HansPassant, create a ticket for this: https://connect.microsoft.com/VisualStudio/feedback/details/2702659 If you also think this is a problem. Please help up voting it.

like image 740
Yuchen Avatar asked May 18 '26 17:05

Yuchen


1 Answers

I have got an email update from Microsoft VC++ team after posting the issue on Microsoft connect https://connect.microsoft.com/VisualStudio/feedback/details/2702659

Thank you for reporting this issue. The next release of the Visual C++ Compiler Toolset will issue an error when a member of a value class has a default member initializer.

like image 158
Yuchen Avatar answered May 21 '26 07:05

Yuchen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!