codeDom codeDom - 2 months ago 12
C++ Question

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

I work with TaskScheduler COM, this is my code:

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

static bool GetBool(FuncOfBoll func)
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?


I am guessing that get_StopIfGoingOnBatteries is a member function ofITaskSettings. Such a function cannot be used when the expected argument type is FuncOfBoll. You'll need to create a wrapper function and use it.

ITaskSettings* currentSetttings = NULL;

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

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