gpt4 book ai didi

C++ Visual Studio 2015 “non-standard syntax; use ' &' to create a pointer to member”

转载 作者:行者123 更新时间:2023-11-28 00:00:15 26 4
gpt4 key购买 nike

我使用 TaskScheduler COM,这是我的代码:

typedef HRESULT(*FuncOfBoll)(_Out_ VARIANT_BOOL* b);

static bool GetBool(FuncOfBoll func)
{
VARIANT_BOOL b = VARIANT_FALSE;
HRESULT hr = func(&b);
if (FAILED(hr)) return FALSE;
return b == VARIANT_TRUE;
}

void test(ITaskSettings* settings)
{
bool b = GetBool(settings->get_StopIfGoingOnBatteries); // <= The error here
// ...
}

我收到以下错误:

Error C3867 'ITaskSettings::get_StopIfGoingOnBatteries': non-standard syntax; use '&' to create a pointer to member

我的错误是什么以及如何改正?

最佳答案

我猜测 get_StopIfGoingOnBatteriesITaskSettings 的成员函数。当期望的参数类型是 FuncOfBoll 时,不能使用这样的函数。您需要创建一个包装函数并使用它。

ITaskSettings* currentSetttings = NULL;

HRESULT GetBoolWrapper(_Out_ VARIANT_BOOL* b)
{
return currentSetttings->get_StopIfGoingOnBatteries(b);
}

void test(ITaskSettings* settings)
{
currentSetttings = settings;
bool b = GetBool(GetBoolWrapper);
}

关于C++ Visual Studio 2015 “non-standard syntax; use ' &' to create a pointer to member”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39622640/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com