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 :: c++ rainbow text 
Cpp :: dualSort 
Cpp :: multiply two arbitrary integers a and b (a greater than b) 
Cpp :: 771. Jewels and Stones leetcode solution in c++ 
Cpp :: how to make negative number positive in c++ 
Cpp :: http://dcnet.ddns.ma/Connecter_Tuteur 
Cpp :: bullet physics directx 11 
Cpp :: char * in c++ 
Cpp :: scope resolution operator in c++ 
Cpp :: How to get the last element of an array in C++ using std::array 
Cpp :: how to convert n space separated integers in c++ 
Cpp :: stack in c++ 
Cpp :: how to include a library in arduino 
Cpp :: void pointer c++ 
Cpp :: x += c++ 
Cpp :: string array 2d c++ 
Cpp :: do while loop c++ 
C :: malloc is undefined 
C :: full installation of clang in ubuntu 
C :: c get time 
C :: print boolean value in c 
C :: c how to get an integer from user input 
C :: C program to display fibonacci serice 
C :: how to read character from a string in c 
C :: string compare c 
C :: how to print value of pointer in c 
C :: how to check if a string pointer is empty in c 
C :: Hello world in C programming language 
C :: c check if array is empty 
C :: C Arithmetic Operators 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =