简体   繁体   中英

Why I am getting C3646 on an IAsyncAction declaration?

Probably a dumb question (WinRT noob), but, here is goes...

The code from "App.xaml.h" is:

namespace winrt::Precog::implementation
{
    struct App : AppT<App>
    {
        App();

        void OnLaunched(Microsoft::UI::Xaml::LaunchActivatedEventArgs const&);

    private:
        std::wstring cfgDatabase = L"";
        winrt::Microsoft::UI::Xaml::Window window{ nullptr };

        IAsyncAction loadSettings();
    };
}

When I try to compile, Visual Studio gives me a C3646 (unknown override specifier) at the IAsyncAction declaration?

The loadSettings implementation is:

IAsyncAction App::loadSettings()
{
    PHKEY regKey = NULL;
    LSTATUS regResult;

    regResult = RegCreateKey(HKEY_CURRENT_USER, L"Precog", regKey);
    if (regResult != ERROR_SUCCESS)
    {
        ContentDialog errorDialog = ContentDialog();
        errorDialog.Title(box_value(L"Erro"));
        errorDialog.Content(box_value(L"Pateta"));
        errorDialog.CloseButtonText(L"Ok");
        errorDialog.XamlRoot(window.Content().XamlRoot());
        auto result = co_await errorDialog.ShowAsync();
    }
    else
    {
        co_return;
    }
}

EDIT: Full compiler output:

Build started...
1>------ Build started: Project: Precog, Configuration: Debug x64 ------
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2304,5): warning MSB3106: Assembly strong name "C:\Code\Precog\packages\Microsoft.WindowsAppSDK.1.0.0\build\native\..\..\lib\uap10.0\Microsoft.Windows.System.winmd" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\).
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2304,5): warning MSB3106: Assembly strong name "C:\Code\Precog\packages\Microsoft.WindowsAppSDK.1.0.0\build\native\..\..\lib\uap10.0\Microsoft.Windows.PushNotifications.winmd" is either a path which could not be found or it is a full assembly name which is badly formed. If it is a full assembly name it may contain characters that need to be escaped with backslash(\). Those characters are Equals(=), Comma(,), Quote("), Apostrophe('), Backslash(\).
1>App.xaml.cpp
1>C:\Code\Precog\Precog\Precog\App.xaml.h(17,22): error C3646: 'loadSettings': unknown override specifier
1>C:\Code\Precog\Precog\Precog\App.xaml.h(17,34): error C2059: syntax error: '('
1>C:\Code\Precog\Precog\Precog\App.xaml.h(17,36): error C2238: unexpected token(s) preceding ';'
1>C:\Code\Precog\Precog\Precog\App.xaml.cpp(35,19): error C2039: 'loadSettings': is not a member of 'winrt::Precog::implementation::App'
1>C:\Code\Precog\Precog\Precog\App.xaml.h(7): message : see declaration of 'winrt::Precog::implementation::App'
1>C:\Code\Precog\Precog\Precog\App.xaml.cpp(48,30): error C2065: 'window': undeclared identifier
1>Done building project "Precog.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Got it. It seemed to be a namespace mismatch, since changing the declaration to:

winrt::Windows::Foundation::IAsyncAction loadSettings();

Solved the problem. The interesting bit is that Intellisense does not catch the error (no red line underneath the type), only the compiler does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM