Search
 
SCRIPT & CODE EXAMPLE
 

CPP

C++ Initializing a thread with a class/object

class myFunc
{
public:
  void function() (/* No Parameters */)
  {
    cout << "myFunc object." << endl;
  }
};

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

myFunc myFunc1;

thread thread1(myFunc1);

if (thread1.joinable())
{
thread1.join();
}
Comment

C++ initializing a thread with a public function of a class


class myFunc
{
public:
  void pubFunc1()
  {
    cout << "publicFunc1 of myFunc class called" << endl;
  }
};

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

myFunc myFunc1;

thread thread1(&myFunc::pubFunc1,myFunc);

if (thread1.joinable())
{
	thread1.join();
}
Comment

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();
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: preorder to postorder converter online 
Cpp :: convert char to string c++ 
Cpp :: input many numbers to int c++ 
Cpp :: map::begin 
Cpp :: sort vector from smallest to largest 
Cpp :: Use of Scope Resolution operator for namespace 
Cpp :: how to calculate 2^7 in cpp code 
Cpp :: Data Encapsulation in C++ 
Cpp :: C++ selectin file location using Win32 API 
Cpp :: stack using cpp 
Cpp :: c++ Detect Cycle in a Directed Graph 
Cpp :: Diamond pattren program in C++ 
Cpp :: run program until ctrl-d c++ 
Cpp :: armstrong number 
Cpp :: linked 
Cpp :: find the number of digits of a given integer n . 
Cpp :: iff cpp 
Cpp :: cpp reference array 
Cpp :: 130 divided by -10 
Cpp :: https://www.google 
Cpp :: cuda allocate memory 
Cpp :: time out search element in linked list c++ 
Cpp :: how to define global array in c++ in a scope 
Cpp :: C++ concept simple requirements 
Cpp :: how can I convert each and every element of string push into set in c++? 
Cpp :: c++ else 
Cpp :: beecrowd problem 1001 solution 
Cpp :: Casino Number Guessing Game - C++ 
Cpp :: c++ set element at index 
Cpp :: c++ quicksort 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =