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 :: use textchanged qt cpp 
Cpp :: return multiple values c++ 
Cpp :: input numbers to int c++ 
Cpp :: c++ get microseconds since epoch 
Cpp :: Minimizing the dot product codechef in c++ 
Cpp :: sort array in descending order c++ 
Cpp :: copy file to vector c++ 
Cpp :: prompt user for bool statement C++ 
Cpp :: const in c++ is same as globle in python 
Cpp :: Summation of Natural Number Sequence with c and c++. 
Cpp :: c++ localtime unsafe 
Cpp :: opengl draw cresent moon c++ 
Cpp :: A Subtask Problem codechef solution in cpp 
Cpp :: pimpl c++ 
Cpp :: c++ conditional typedef 
Cpp :: what do I return in int main() function c++ 
Cpp :: lru cache gfg 
Cpp :: C++ std::ofstream class members 
Cpp :: Difference Array | Range update query in O 
Cpp :: how to compile with libstdc++ fedora 
Cpp :: C++ (.NET CLI) 
Cpp :: output sum of a range 
Cpp :: sfml get position 
Cpp :: last element of a set in c++ 
Cpp :: how to user input in string to open files in c++ 
Cpp :: copy constructor in c++ questions 
Cpp :: run a c++ file in terminal 
Cpp :: convert "c++ to c" code online 
Cpp :: C++ Features 
Cpp :: 2d vector size c++ 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =