小编Wuy*_*283的帖子

用于回调函数的lambda表达式失败,当我尝试caputre [this]时,为什么?

我需要使用一个DLL库,它给我一个定义如下的回调函数:

typedef void  ( __stdcall *PAmsRouterNotificationFuncEx)( long nEvent );
Run Code Online (Sandbox Code Playgroud)

用于注册回调函数的函数是:

bool RigisterStatusMonitorFunc(PAmsRouterNotificationFuncEx fpFuncAMS);
Run Code Online (Sandbox Code Playgroud)

我试着像这样调用它(在一个按钮处理函数中):

auto fpTc2RouterCall = [](LONG nReason){
    switch (nReason)
    {
    case AMSEVENT_ROUTERSTOP:
        ...
        break;
    case AMSEVENT_ROUTERSTART:
        ...
        break;
    case AMSEVENT_ROUTERREMOVED:
        ...
        break;
    default:
        ...
        break;
    }
};
…… ……

RigisterStatusMonitorFunc(fpTc2RouterCall);  //It works.
Run Code Online (Sandbox Code Playgroud)

但是当我在caputure列表中添加[this]时,它不起作用!为什么?

auto fpTc2RouterCall = [this](LONG nReason){
    switch (nReason)
    {
    case AMSEVENT_ROUTERSTOP:
        ...
        StopAMS();   //Member function of this class,I need call it in the lambda expression.
        break;
    case AMSEVENT_ROUTERSTART:
        ...
        break;
    case AMSEVENT_ROUTERREMOVED:
        ...
        break;
    default:
        ... …
Run Code Online (Sandbox Code Playgroud)

c++ lambda

2
推荐指数
1
解决办法
84
查看次数

对于长型是否有Math.Pow(A,n)函数?

我正在测试一个小的C#程序片段:

        short min_short = (short)(int)-Math.Pow(2,15);   
        short max_short = (short)(int)(Math.Pow(2, 15) - 1);
        Console.WriteLine("The min of short is:{0};\tThe max of short is:{1}", min_short, max_short);

        int min_int = (int)-Math.Pow(2, 31);
        int max_int = (int)(Math.Pow(2, 31) - 1);
        Console.WriteLine("The min of int is:{0};\tThe max of int is:{1}", min_int, max_int);

        uint min_uint = 0;
        uint max_uint = (uint)(Math.Pow(2, 32) - 1);
        Console.WriteLine("The min of uint is:{0};\tThe max of uint is:{1}", min_uint, max_uint);

        long min_long = (long)-Math.Pow(2, 63);
        long max_long = (long)(Math.Pow(2, 63) - 1); …
Run Code Online (Sandbox Code Playgroud)

c# math pow

1
推荐指数
1
解决办法
2683
查看次数

标签 统计

c# ×1

c++ ×1

lambda ×1

math ×1

pow ×1