Jens Luedicke Jens Luedicke - 1 year ago 85
C++ Question

How to pass parameters to a Thread object?

I'm working with a C++ class-library that provides a Thread base-class where the user has to
implement a


Is there a recommended way on how to pass parameters to that
method? Right now
I prefer to pass them via the constructor (as pointers).

Answer Source

I'm not sure about C++, but that's how you would do it in Java. You'd have a class that extends Thread (or implements Runnable) and a constructor with the parameters you'd like to pass. Then, when you create the new thread, you have to pass in the arguments, and then start the thread, something like this:

Thread t = new MyThread(args...);

Must be the same in your case.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download