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 9109749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:07:05+00:00 2026-06-17T03:07:05+00:00

I am trying to understand how to use the new std::thread using Visual Studio

  • 0

I am trying to understand how to use the new std::thread using Visual Studio 2012. I am trying to compile the following code.

#include <iostream>
#include <thread>

class scoped_thread
{
    std::thread t_;

public:

    explicit scoped_thread(std::thread & t): t_(std::move(t))
    {
        if(!t_.joinable())throw std::logic_error("No thread");
    }

    ~scoped_thread()
    {
        t_.join();
    }

private:

    scoped_thread(scoped_thread const &);
    scoped_thread & operator=(scoped_thread const &);
};

struct local_functor
{
    int& i_;

    local_functor(int & i):i_(i){}

    void operator()()
    {
        while(i_ < 1e5)i_++;        
    }
};

// can potentially throw exceptions
void callAnotherFunc()
{
    std::cout << "this function can throw an exception" << std::endl;   
    // try (un)commenting the line below and see the behaviour
    throw std::out_of_range("WTF2");
}


int main()
{
    int some_local_state =  0;

    try
    {   
        scoped_thread t(std::thread(local_functor(some_local_state)));
        callAnotherFunc();

        std::cout << "Proper exit of function" << std::endl;
    }
    catch(const std::exception & e)
    {
        std::cout << e.what() << " exception occurred!" << std::endl;
    }
    catch(...)
    {
        std::cout << "Unhandled exception!" << std::endl;
    }

    return 0;
}

I am getting a warning that says
warning C4930: ‘scoped_thread t(std::thread (__cdecl *)(local_functor))’: prototyped function not called (was a variable definition intended?)

Yes, it was a variable definition that was intended. How am I supposed to do that?

  • 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-17T03:07:06+00:00Added an answer on June 17, 2026 at 3:07 am

    The warning tells you, that the first line in your try block is parsed as a function declaration. That happes sometimes if you use C++03 initialization style. Use uniform initialization instead:

    scoped_thread t{std::thread{local_functor{some_local_state}}};
    

    In addition, you have a missing & in the scoped_thread constructor:

    explicit scoped_thread(std::thread && t): t_(std::move(t))
    //                                 ^-- use r-value ref
    

    PS:
    If your compiler does not support uniform initialization, wrap the initializer into another pair of brackets: scoped_thread t((std::thread(local_functor(some_local_state))));

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

Sidebar

Related Questions

I am trying to understand the following bit of code: #include<iostream> using namespace std;
I am new to salesforce and apex as well. trying to use to understand
I'm trying to understand how the new try-with-resources statement works by recreating it using
I'm new at using CoreData and I'm trying to understand how to perform a
#include <stdio.h> #include <iostream> using namespace std; int main(void) { bool premiereLignefaite = false;
I'm pretty new to Django and right now I'm trying to understand the use
I´m trying to understand and use the Picasa Api, I´m using this example https://developers.google.com/picasa-web/docs/2.0/developers_guide_java?hl=nl-NL
I'm new to JavaScript and trying to understand the behavior of this code, which
I am learning Django and I am trying to understand the use of models.py
I'm trying to understand how to use firebug to debug my Javascript. So I

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.