I work with TaskScheduler COM, this is my code:
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
// ...
}
and I get the following error:
Error C3867 'ITaskSettings::get_StopIfGoingOnBatteries': non-standard syntax; use '&' to create a pointer to member
What is my mistake and how to correct it?
This is not really an answer, the question as written doesn't admit an answer, but this is too long & detailed for comment.
You don't show a full examples, so there has to be guesswork.
Apparently, judging by the error message,
settings
is a pointer to class type object, where that class has a member functionget_StopIfGoingOnBatteries
.And apparently, judging by the use of
->
operator, it's a non-static
member function. You could still use->
if it werestatic
, but that would be unnatural. So let's say it's a non-static
member function.Then you can't easily form a raw pointer to function that calls that member function, because you need a
this
-pointer for the call. It could just use a dummy object, if creation of such object is cheap, or it could use a global instance or pointer to instance. But better change something in your design, and/or explain more clearly what you want.The correct definition for a pointer to member function is:
Then, you should pass the pointer to the object instance to function
GetBool
:Or, with template:
Invocation:
I am guessing that
get_StopIfGoingOnBatteries
is a member function ofITaskSettings
. Such a function cannot be used when the expected argument type isFuncOfBoll
. You'll need to create a wrapper function and use it.