一種類型,可用來宣告您自己的事件的自定義委派類型。 delegate supports any number of parameters, and they are not limited to Windows Runtime types.
The delegate type has no ABI (it has no interface for use across application binaries), so its use case is when you're both authoring and consuming an event within the same project. 如需該案例的詳細資訊,請參閱 專案內的參數化委派、簡單訊號和回呼。
如需處理事件和程式代碼範例的詳細資訊,請參閱 在 C++/WinRT 中使用委派來處理事件。
Syntax
template <typename... T>
struct delegate : Windows::Foundation::IUnknown
Template parameters
typename... T 包含呼叫委派時傳遞之參數類型的 variadic 範本參數套件。
Requirements
支援的最低 SDK: Windows SDK 版本 10.0.17134.0(Windows 10 版本 1803)
Namespace: winrt
Header: %WindowsSdkDir%Include<WindowsTargetPlatformVersion>\cppwinrt\winrt\base.h (included by default)
Constructors
| Constructor | Description |
|---|---|
| delegate::delegate constructor | Initializes a new instance of the delegate struct from the input data. |
Member operators
| Operator | Description |
|---|---|
| delegate::operator() (函數調用運算子) | Invokes the delegate represented by the delegate object with the provided arguments. |
delegate::delegate constructor
Initializes a new instance of the delegate struct from the input data.
Syntax
delegate(std::nullptr_t = nullptr) noexcept; // (1)
template <typename L>
delegate(L lHandler); // (2)
template <typename F>
delegate(F* fHandler); // (3)
template <typename O, typename M>
delegate(O* object, M method); // (4)
template <typename O, typename M>
delegate(winrt::com_ptr<O>&& object, M method); // (5)
template <typename O, typename M>
delegate(winrt::weak_ref<O>&& object, M method); // (6)
template <typename O, typename M>
delegate(winrt::weak_ref<O>&& object, L lHandler); // (7)
template <typename O, typename M>
delegate(std::shared_ptr<O>&& object, M method); // (8)
template <typename O, typename M>
delegate(std::weak_ptr<O>&& object, M method); // (9)
template <typename O, typename M>
delegate(std::weak_ptr<O>&& object, L lHandler); // (10)
Template parameters
typename L Lambda 類型,或更普遍地支援函式呼叫語法的任何類型,例如 std::function。
typename F 免費函式類型。
typename O 物件類型。
typename M 指針對成員函式類型。
Parameters
lHandler Lambda 物件,或更通常支援函式呼叫語法的物件,例如 std::function,將處理事件。
fHandler 將處理事件的指針對任意函式。
object 物件,其中一個成員函式將處理事件。
視多載而定,此物件可能由原始指標或智慧型手機表示。
method 將處理事件的指針對成員函式。
Remarks
默認建構函式 (1) 會建構空委派。
建構函式 (2) 建構委派,此委派會呼叫具有委派自變數的 Lambda。
建構函式 (3) 建構委派,此委派會使用委派自變數呼叫函式。
建構函式 (4) 建構委派,此委派會使用委派自變數呼叫指向物件的方法。
建構函式 (5) 建構委派,此委派會使用委派自變數呼叫參考物件的方法。
建構函式 (6) 建構委派,其會嘗試解析 weak_ref 為強式參考。
如果成功,則會使用委派自變數呼叫物件的方法;否則,它不會執行任何動作。
建構函式 (7) 建構委派,此委派會嘗試解析 weak_ref 為強式參考。
如果成功,則會使用委派自變數呼叫 Lambda;否則,它不會執行任何動作。
需要 C++/WinRT 2.0.240111.5 版。
建構函式 (8) 建構委派,此委派會使用委派自變數呼叫共享物件的方法。 需要 C++/WinRT 2.0.240111.5 版。
建構函式 (9) 建構委派,此委派會嘗試解析 weak_ptr 為共用指標。
如果成功,則會使用委派自變數呼叫共享物件的方法;否則,它不會執行任何動作。
需要 C++/WinRT 2.0.240111.5 版。
建構函式 (10) 建構委派,此委派會嘗試解析 weak_ptr 為共用指標。
如果成功,則會使用委派自變數呼叫 Lambda;否則,它不會執行任何動作。
需要 C++/WinRT 2.0.240111.5 版。
delegate::operator() (函數調用運算子)
Invokes the delegate represented by the delegate object with the provided arguments.
Syntax
void operator()(T const&... args) const