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

  • Home
  • SEARCH
  • 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 8983499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:51:21+00:00 2026-06-15T20:51:21+00:00

I am trying to spawn a thread from within my class and the thread

  • 0

I am trying to spawn a thread from within my class and the thread executes a particular method in my class. The code looks like this:

class ThreadClass{
    int myThread(int arg){
     // do something
    }

    void createThread(){
        thread t = thread(myThread,10);
    }

} ;

This code on compilation throws an error saying

std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = int (ThreadClass::*)(int), _Args = {int}]
no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘int (ThreadClass::*&&)(int)’

I am not sure what is the actual bug here. Can someone help me with this?

Thanks.

  • 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-15T20:51:22+00:00Added an answer on June 15, 2026 at 8:51 pm

    The problem is that a member function can’t be called without an object. Provide a pointer to this so that the current object is used:

    thread t(&ThreadClass::myThread, this, 10);
    

    You could use an instance of any ThreadClass object, but in your case, it seems this is the right thing to do.

    NOTE: Remember you need a reference to the created thread so that you can do a join() later on.

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

Sidebar

Related Questions

I am trying to spawn a thread for just 1 method. Im getting an
I got an EAGAIN when trying to spawn a thread using pthread_create. However, from
Well, Im trying to spawn a process from inside a thread spawned by a
I am trying to launch a background thread to retrieve XML data from a
I am trying to spawn a thread to take care of DoWork task that
I am trying to have my main thread spawn off a new thread and,
I am running some CPU-intensive Clojure code from within Intellij Idea (I don't think
I'm trying to implement the code from showing dialog while loading layout by setContentView
I am trying to call my BHO method from the javascript. The problem is
I am trying to spawn a process using Runtime.exec. I want to use my

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.