System::Func class
コンテンツ
[
隠れる
]Func class
関数デリゲートです。この型はスタック上に割り当て、値または参照で関数に渡すべきです。System::SmartPtr クラスを使用してこの型のオブジェクトを管理しないでください。
template<typename...>class Func : public System::MulticastDelegate<::System::Detail::FuncArgsReorderer<void(), Args...>::type>
| パラメーター | 説明 |
|---|---|
| 引数 | 呼び出し引数、その後必須の戻り値の型。 |
メソッド
| メソッド | 説明 |
|---|---|
| Func() | null-Func を作成するデフォルトコンストラクタです。 |
| Func(T&&) | Func オブジェクトを構築し、値(実際のコールバックまたは nullptr のいずれか)を割り当てるコンストラクタです。 |
| Func(const Func&) | コピーコンストラクタ。 |
| Func(Func&&) | ムーブコンストラクタ。 |
| operator=(const Func&) | コピー代入。 |
| operator=(Func&&) | ムーブ代入。 |
| ~Func() | デストラクタ。 |
備考
#include "system/func.h"
#include <iostream>
// この関数はパラメータとして System::Func デリゲートのインスタンスを受け取ります。
void Print(int x, const System::Func<int, int> &func)
{
std::cout << func(x) << std::endl;
}
int main()
{
// System::Func デリゲートのインスタンスを作成します。
auto func = static_cast<System::Func<int, int>>([](int x) -> int
{
return x * x;
});
// 作成したインスタンスを関数引数として渡します。
Print(1, func);
Print(2, func);
Print(3, func);
return 0;
}
/*
This code example produces the following output:
1
4
9
*/
参照
- Namespace System
- Library Aspose.Page for C++