fork download
  1. class jThread
  2. {
  3. private:
  4. bool Alive;
  5. HANDLE hThread;
  6. public:
  7. jThread() : Alive(false), hThread(NULL)
  8. {
  9.  
  10. }
  11. virtual ~jThread()
  12. {
  13. CloseHandle(hThread);
  14. }
  15. void Start()
  16. {
  17. if( !Alive )
  18. {
  19. hThread = (HANDLE) _beginthreadex(NULL,0,Ready,this,NULL,NULL);
  20.  
  21. if(hThread == NULL)
  22. {
  23. throw std::bad_alloc("스레드 생성과정에서 에러가 발생했습니다.");
  24. }
  25.  
  26. Alive = true;
  27. }
  28. }
  29. void Pause()
  30. {
  31. SuspendThread(hThread);
  32. }
  33. void Resume()
  34. {
  35. ResumeThread(hThread);
  36. }
  37. void Join()
  38. {
  39. WaitForSingleObject(hThread,INFINITE);
  40. }
  41.  
  42. const bool IsAlive() const
  43. {
  44. return this->Alive;
  45. }
  46.  
  47. private:
  48. static unsigned int __stdcall Ready(void* ptr)
  49. {
  50. jThread* ThisPtr = (jThread*)ptr;
  51.  
  52. ThisPtr->Run();
  53. ThisPtr->Alive = false;
  54. return 0;
  55. }
  56. protected:
  57. virtual void Run()
  58. {
  59. printf("Thread");
  60. }
  61.  
  62. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:5:2: error: ‘HANDLE’ does not name a type
  HANDLE hThread;
  ^
prog.cpp:48:22: error: expected ‘;’ at end of member declaration
  static unsigned int __stdcall Ready(void* ptr)
                      ^
prog.cpp:48:47: error: ISO C++ forbids declaration of ‘Ready’ with no type [-fpermissive]
  static unsigned int __stdcall Ready(void* ptr)
                                               ^
prog.cpp: In constructor ‘jThread::jThread()’:
prog.cpp:7:28: error: class ‘jThread’ does not have any field named ‘hThread’
  jThread() : Alive(false), hThread(NULL)
                            ^
prog.cpp:7:36: error: ‘NULL’ was not declared in this scope
  jThread() : Alive(false), hThread(NULL)
                                    ^
prog.cpp: In destructor ‘virtual jThread::~jThread()’:
prog.cpp:13:15: error: ‘hThread’ was not declared in this scope
   CloseHandle(hThread);
               ^
prog.cpp:13:22: error: ‘CloseHandle’ was not declared in this scope
   CloseHandle(hThread);
                      ^
prog.cpp: In member function ‘void jThread::Start()’:
prog.cpp:19:4: error: ‘hThread’ was not declared in this scope
    hThread = (HANDLE) _beginthreadex(NULL,0,Ready,this,NULL,NULL);
    ^
prog.cpp:19:15: error: ‘HANDLE’ was not declared in this scope
    hThread = (HANDLE) _beginthreadex(NULL,0,Ready,this,NULL,NULL);
               ^
prog.cpp:19:23: error: expected ‘;’ before ‘_beginthreadex’
    hThread = (HANDLE) _beginthreadex(NULL,0,Ready,this,NULL,NULL);
                       ^
prog.cpp:21:18: error: ‘NULL’ was not declared in this scope
    if(hThread == NULL)
                  ^
prog.cpp:23:11: error: ‘bad_alloc’ is not a member of ‘std’
     throw std::bad_alloc("스레드 생성과정에서 에러가 발생했습니다.");
           ^
prog.cpp: In member function ‘void jThread::Pause()’:
prog.cpp:31:17: error: ‘hThread’ was not declared in this scope
   SuspendThread(hThread);
                 ^
prog.cpp:31:24: error: ‘SuspendThread’ was not declared in this scope
   SuspendThread(hThread);
                        ^
prog.cpp: In member function ‘void jThread::Resume()’:
prog.cpp:35:16: error: ‘hThread’ was not declared in this scope
   ResumeThread(hThread);
                ^
prog.cpp:35:23: error: ‘ResumeThread’ was not declared in this scope
   ResumeThread(hThread);
                       ^
prog.cpp: In member function ‘void jThread::Join()’:
prog.cpp:39:23: error: ‘hThread’ was not declared in this scope
   WaitForSingleObject(hThread,INFINITE);
                       ^
prog.cpp:39:31: error: ‘INFINITE’ was not declared in this scope
   WaitForSingleObject(hThread,INFINITE);
                               ^
prog.cpp:39:39: error: ‘WaitForSingleObject’ was not declared in this scope
   WaitForSingleObject(hThread,INFINITE);
                                       ^
prog.cpp: In member function ‘virtual void jThread::Run()’:
prog.cpp:59:18: error: ‘printf’ was not declared in this scope
   printf("Thread");
                  ^
stdout
Standard output is empty