fork download
  1. class CallableClass
  2. {
  3. private:
  4. // Number of iterations
  5. int m_iterations;
  6.  
  7. public:
  8.  
  9. // Default constructor
  10. CallableClass()
  11. {
  12. m_iterations=10;
  13. }
  14.  
  15. // Constructor with number of iterations
  16. CallableClass(int iterations)
  17. {
  18. m_iterations=iterations;
  19. }
  20.  
  21.  
  22. // Copy constructor
  23. CallableClass(const CallableClass& source)
  24. {
  25. m_iterations=source.m_iterations;
  26. }
  27.  
  28. // Destructor
  29. ~CallableClass()
  30. {
  31. }
  32.  
  33. // Assignment operator
  34. CallableClass& operator = (const CallableClass& source)
  35. {
  36. m_iterations=source.m_iterations;
  37. return *this;
  38. }
  39.  
  40. // Static function called by thread
  41. static void StaticFunction()
  42. {
  43. for (int i=0; i < 10; i++) // Hard-coded upper limit
  44. {
  45. cout<<i<<"Do something in parallel (Static function)."<<endl;
  46. boost::this_thread::yield(); // 'yield' discussed in section 18.6
  47. }
  48. }
  49.  
  50. // Operator() called by the thread
  51. void operator () ()
  52. {
  53. for (int i=0; i<m_iterations; i++)
  54. {
  55. cout<<i<<" - Do something in parallel (operator() )."<<endl;
  56. boost::this_thread::yield();
  57. }
  58. }
  59.  
  60. };
  61.  
  62.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In static member function ‘static void CallableClass::StaticFunction()’:
prog.cpp:45:2: error: ‘cout’ was not declared in this scope
  cout<<i<<"Do something in parallel (Static function)."<<endl;
  ^~~~
prog.cpp:45:58: error: ‘endl’ was not declared in this scope
  cout<<i<<"Do something in parallel (Static function)."<<endl;
                                                          ^~~~
prog.cpp:46:2: error: ‘boost’ has not been declared
  boost::this_thread::yield(); // 'yield' discussed in section 18.6
  ^~~~~
prog.cpp: In member function ‘void CallableClass::operator()()’:
prog.cpp:55:2: error: ‘cout’ was not declared in this scope
  cout<<i<<" - Do something in parallel (operator() )."<<endl;
  ^~~~
prog.cpp:55:57: error: ‘endl’ was not declared in this scope
  cout<<i<<" - Do something in parallel (operator() )."<<endl;
                                                         ^~~~
prog.cpp:56:2: error: ‘boost’ has not been declared
  boost::this_thread::yield();
  ^~~~~
stdout
Standard output is empty