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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:49:06+00:00 2026-05-15T16:49:06+00:00

I have a function in my class that creates a thread and gives it

  • 0

I have a function in my class that creates a thread and gives it arguments to call a function which is part of that class but since thread procs must be static, I can’t access any of the class’s members. How can this be done without using a bunch of static members in the cpp file to temporarily give the data to be manipulated, this seems slow.

Heres an example of what I mean:

in cpp file:

void myclass::SetNumber(int number)
{
   numberfromclass = number;
}

void ThreadProc(void *arg)
{

   //Can't do this
   myclass::SetNumber((int)arg);
}

I can’t do that since SetNumber would have to be static, but I instance my class a lot so that won’t work.

What can I do?

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-05-15T16:49:08+00:00Added an answer on May 15, 2026 at 4:49 pm

    Usually you specify the address of the object of myclass as arg type and cast it inside the ThreadProc. But then you’ll be blocked on how passing the int argument.

    void ThreadProc(void *arg)
    {
       myclass* obj = reinterpret_cast<myclass*>(arg);
       //Can't do this
       obj->SetNumber(???);
    }
    

    As you said this is maybe not only a bit slow but it also clutters the code. I would suggest to use boost::bind for argument binding and to create the threads in an os independent way (for your own source at least) you could use boost::thread. Then no need for static methods for your threads.

    Now in the C++0x standard, here a small tutorial

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

Sidebar

Ask A Question

Stats

  • Questions 488k
  • Answers 488k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Reflector Pro Visual Studio plug in can debug not only… May 16, 2026 at 8:43 am
  • Editorial Team
    Editorial Team added an answer OData is a great fit for your client-server application. For… May 16, 2026 at 8:43 am
  • Editorial Team
    Editorial Team added an answer You can use the os module to check for the… May 16, 2026 at 8:43 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a custom thread pool class, that creates some threads that each wait
I have a class which is being operated on by two functions. One function
In C++, I have a certain template function that, on a given condition, calls
I have a simple question, but I'm about 80% sure that the answer to
I have a DBAdmin class that connects to the database, and then some other
I have a layout that creates a ListActivity. Before displaying the ListActivity, I perform
Let's say I want to create a collection class that is thread-safe by default.
I have a block of code that runs within a TransactionScope and within this
I have an application that performs a write to a database each time a
I created a class that handles serial port asynchronously. I use it to communicate

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.