共用方式為


MatchEventInMemberFunction

C++ Build Insights SDK 與 Visual Studio 2017 和更新版本相容。 若要查看這些版本的檔,請將本文的 Visual Studio 版本 選取器控制項設定為 Visual Studio 2017 或更新版本。 其位於此頁面目錄頂端。

MatchEventInMemberFunction 式是用來比對成員函式第一個參數所描述的型別。 相符的事件會轉送至成員函式以進行進一步處理。

語法

template <
    typename     TInterface,
    typename     TReturn,
    typename     TEvent,
    typename...  TExtraParams,
    typename...  TExtraArgs>
bool MatchEventInMemberFunction(
    const RawEvent&          event,
    TInterface*              objectPtr,
    TReturn (TInterface::*   memberFunc)(TEvent, TExtraParams...),
    TExtraArgs&&...          extraArgs);

參數

TInterface
包含成員函式的類型。

TReturn
成員函式的傳回型別。

TEvent
要比對的事件種類。

TExtraParams
成員函式所接受的額外參數類型,以及要比對的事件種類。

TExtraArgs
傳遞至 MatchEventInMemberFunction 的額外引數類型。

event
要與 TEvent 描述之事件種類相符的事件。

objectPtr
要在其中呼叫 memberFunc 之物件的 指標。

memberFunc
描述要比對之事件種類的成員函式。

extraArgs
取得完美轉送給 memberFunc 以及事件種類參數的引數。

傳回值

bool如果比對成功,則 false 為 , true 否則為 。

備註

您可以從擷取類別 清單中選取要用於 TEvent 參數的事件 類型。 如需事件清單和可用來比對的事件擷取類別,請參閱 事件資料表

範例

void MyClass::Foo1(Function f) {}

void MyClass::Foo2(Compiler cl) {}

void MyClass::OnStartActivity(const EventStack& eventStack)
{
    // Let's assume eventStack contains:
    // [Compiler, BackEndPass, C2DLL, CodeGeneration, Thread, Function]

    auto& functionEvent = eventStack.Back(); // The Function event

    bool b1 = MatchEventInMemberFunction(
        functionEvent, this, &MyClass::Foo1);

    bool b2 = MatchEventInMemberFunction(
        functionEvent, this, &MyClass::Foo2);

    // b1: true because the first parameter of Foo1 is Function.
    // b2: false because the first parameter of Foo2 isn't Function.
}