Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8567745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:57:05+00:00 2026-06-11T17:57:05+00:00

I am using g++ 4.7 with the c++11 flag. In this demo: #include <iostream>

  • 0

I am using g++ 4.7 with the c++11 flag. In this demo:

#include <iostream>
#include <thread>

class do_work
{
public:
   void operator()()
   {
     std::cout << "Doing work..." << std::endl;
   }
};

void foo()
{

}

int main()
{
  // Does not work
  std::thread t(do_work);
  t.join(); // error: request for member ‘join’ in ‘t’, which is of non-class type ‘std::thread(do_work)’

  // Works
  std::thread t2(foo);
  t2.join();

  return 0;
}

I can successfully call join() on a thread that was created with a function as its constructor argument, but I cannot call join() (see the error inline) on a thread that was created with a functor as its constructor argument. Can anyone explain this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:57:07+00:00Added an answer on June 11, 2026 at 5:57 pm

    You’ve declared t as a function taking do_work and returning std::thread.

    You probably want to write

    do_work worker;
    std::thread t{worker};
    

    or

    std::thread t{do_work{}};
    

    or

    std::thread t((do_work()));
    

    Note that

    std::thread t(do_work());
    

    won’t work; it’s vexingly parsed as declaring a function t taking a function that takes no arguments and returns do_work, and returning std::thread. Wrapping the do_work temporary with parentheses or using uniform initializer syntax (at any point) will fix it.

    This is a good reason to get into the habit of using uniform initializer syntax wherever possible; if you’d written

    std::thread t{do_work};  // incorrect
    

    then compilation would have failed on that line instead of the join.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen some zf commands using a flag like this: -p; I couldn't find
I'm trying to monitor the gc activity in my app, using -verbosegc flag. I
I am having trouble using the //TODO flag. When I put the //TODO comment
I'm using InnoSetup for creating my application installers and I set the SetupLogging=yes flag
I am trying to modify a status flag in an XML structure using Javascript.
I am using the following code: <?php $pattern = /(?<item>.*)\:(?<value>.*)(\{(?<flag>.*)_(?<level>.*)\})/i; $subject = item:value{L_300}; preg_match($pattern,
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
So I'm using this pretty standard jquery plugin pattern whereby you can grab an
This is the same issue as in this thread: Security ID Structure Invalid ,
Background I am using the UTF8-CPP class. The vast majority of my strings are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.