共用方式為


編譯程序錯誤 C3779

'function': 傳回 'auto 或 decltype(auto)' 的函式,在定義 'auto 或 decltype(auto)' 之前無法使用

auto無法推斷指定函數調用的傳回型別。 編譯程式在呼叫站臺上沒有足夠的資訊。

備註

當您呼叫具有傳回型別但沒有本文或尾端傳回型別的正向宣告成員函 auto 式時,可能會發生此錯誤。 當編譯程式在具現化範本特製化時找不到候選傳回類型時,您也可以取得此錯誤。 此錯誤的常見原因是缺少介面標頭。 遺漏的型別通常可從後面出現此錯誤的附注中所提及的 typename 判斷。 若要解決此問題,針對您使用的每個類型,請包含類型位於之命名空間的標頭。

範例

下列C++/WinRT 範例會產生 C3779:

// C3779.cpp
#include <winrt/Windows.Gaming.Input.h>

void CheckGamepads()
{
    auto gamepads =
        winrt::Windows::Gaming::Input::Gamepad::Gamepads();
    for (auto&& gamepad : gamepads)
    {
        check(gamepad);
    }
}

此程式代碼會回報錯誤:

C3779.cpp(8): error C3779: winrt::impl::consume_Windows_Foundation_Collections_IIterable<D,winrt::Windows::Gaming::Input::Gamepad>::First': a function that returns 'auto' cannot be used before it is defined
with
[
    D=winrt:::Windows:::Gaming:::Input:::Gamepad
]
note: see declaration of 'winrt::impl::consume_Windows_Foundation_Collections_IIterable<D,winrt::Windows::Gaming::Input::Gamepad>::First'
with
[
    D=winrt::Windows::Gaming::Input::IVisualCollection
]

附註表示傳回型別定義相依 Windows::Foundation::Collections::IIterable於 。 若要解決此問題,請包含其包含命名空間的標頭:

// C3779b.cpp
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Gaming.Input.h>

void CheckGamepads()
{
    auto gamepads =
        winrt::Windows::Gaming::Input::Gamepad::Gamepads();
    for (auto&& gamepad : gamepads)
    {
        check(gamepad);
    }
}

另請參閱

使用 C++/WinRT 取用 API
為什麼我的C++/WinRT 專案收到「consume_Something:傳回 』auto』 的函式在定義之前無法使用」的格式錯誤?