Search
 
SCRIPT & CODE EXAMPLE
 

CPP

C++ using a member function of a class to pass parameters to a thread

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

    for (int i = 0; i != length; ++i)
    {
      cout << arr1[i] << " ";
    }

    cout << "Make negative all elements/integers of array." << endl;

    for (int i = 0; i != length; ++i)
    {
      arr1[i] *= -1;

      cout << arr1[i] << " ";
    }
  }
};

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

int arr2[7] = { -1, -2, -3, -4, -5, -6, -7 };

thread thread1(&myFunc::negativeSign, &myFunc1, arr2, 7);

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

PREVIOUS NEXT
Code Example
Cpp :: selection sort algorithm in cpp 
Cpp :: . Shell sort in c++ 
Cpp :: cout ascii art c++ 
Cpp :: dream speedrun song mp4 
Cpp :: c++ Testing implementation details for automated assessment of sorting algorithms 
Cpp :: how to make a defaule conrstrocr in c++ classes 
Cpp :: transpose function example in c++ 
Cpp :: grepper users assemble 
Cpp :: I/O Redirection in C++ 
Cpp :: cpp get keystroke in console only 
Cpp :: create dynamic variable c++ 
Cpp :: comentar todas linhas de uma vez vs code 
Cpp :: cpp pointer to two dimensional array 
Cpp :: unreal engine c++ bind action to function with parameter 
Cpp :: qt get wireless interface name 
Cpp :: c++ enter name and surname one string 
Cpp :: servicenow cart api 
Cpp :: empty 2d array as a member of a class class c++ 
Cpp :: float to byte array and back c++ with memcpy command 
Cpp :: huffman encoding in c++ 
Cpp :: armstrong number 
Cpp :: find maximum contiguous Sub arrays 
Cpp :: ros pointcloud2 read_points c++ 
Cpp :: return value from a thread 
Cpp :: cpp-variadics/problem? 
Cpp :: printing sub arrays 
Cpp :: syntax of member function in c++ 
Cpp :: displaying m images one window opencv c++ 
Cpp :: how to find the mean and standard deviation of trqiing dataset in pytorch 
Cpp :: 976. Largest Perimeter Triangle leetcode solution in c++ 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =