Answers for "C++ initializing a thread with a class/object with parameters"

C++
0

C++ initializing a thread with a class/object with parameters

class myFunc
{
public:
  void function()(int* arr, int length)
  {
    cout << "Array length: " << length << "...passed to thread1." << endl;
    
    for (int i = 0; i != length; ++i)
    {
      cout << arr[i] << " " << endl;
    }
  }
};

/************************************************************************/

int arr[7] = { 0, 1, 2, 3, 4, 5, 6 };

myFunc myFunc1;

thread thread1(myFunc1, arr, 7);

if (thread1.joinable())
{
  thread1.join();
}
Posted by: Guest on March-19-2022

Code answers related to "C++ initializing a thread with a class/object with parameters"

Browse Popular Code Answers by Language