1

I'm trying to create multiple threads to handle clicking tasks. Now Visual Studio 2015 doesn't display syntax error, however upon compiling I get the error

C3867 'action::Chrome::click': non-standard syntax; use '&' to create a pointer to member

int main()
{
    std::unique_ptr<action::Chrome>chrome(new action::Chrome());
    const std::vector<uint_16>xLocation = { 1155, 1165, 1205, 1245, 1285 };
    std::vector<uint_16>yLocation;

    //Fill yLocation
    //Yada yada, other code

    std::thread task[6];
    for(uint_8 i = 0; i < 6; i++)task[i] = std::thread((chrome->click, xLocation, yLocation[i]));
    for(uint_8 i = 0; i < 6; i++)task[i].join();
}
1
  • Can you please post the declaration of action::Chrome::click? Commented Sep 29, 2015 at 9:16

1 Answer 1

4

You get a pointer to the member function with &action::Chrome::click, not chrome->click.

If you pass a pointer-to-member-function, the second parameter is supposed to be the object that the function is "called on".

There's also a problem with your parameter list; the extra parentheses mean that you're only passing yLocation[i] to the thread's constructor.

Use

std::thread(&action::Chrome::click, chrome, xLocation, yLocation[i]);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the explanation and how to resolve it. Although changing the code to the one you provided, an error occurred with the unique_ptr which was easily fixed by using shared_ptr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.