2012-04-02 70 views
6

我得到了上面的錯誤信息(我Google搜索到,發現是與一個缺少的大括號或東西有關),但是,我看不到這個缺少的括號是哪裏?致命錯誤C1004:發現意外的文件結尾

#include "stdafx.h" 
#include <Windows.h> 
#include <iostream> 
using namespace std; 

    class Something{ 


     static DWORD WINAPI thread_func(LPVOID lpParameter) 
     { 
      thread_data *td = (thread_data*)lpParameter; 
      cout << "thread with id = " << td->m_id << endl; 
      return 0; 
     } 


     int main() 
     { 
      for (int i=0; i< 10; i++) 
      { 
       CreateThread(NULL, 0, thread_func, new thread_data(i) , 0, 0); 
      } 

      int a; 

      cin >> a; 
     } 

     struct thread_data 
     { 
      int m_id; 
      thread_data(int id) : m_id(id) {} 
     }; 

    } 
+0

只是好奇,爲什麼'main'包裝在一個類中? – Mahesh 2012-04-02 15:01:26

+0

從這裏得到了示例:http://stackoverflow.com/questions/4768294/multithreading-in-c – mezamorphic 2012-04-02 15:07:13

+0

我認爲它必須包裝在一個類中? – mezamorphic 2012-04-02 15:07:22

回答

21

在C++中,class關鍵字需要閉括號之後的分號:所述class Something定義的閉括號(})後

class Something { 

}; // <-- This semicolon character is missing in your code sample. 
+0

謝謝!它現在說「致命錯誤LNK1120:1個未解決的外部事件」對不起,我是一名Java開發人員! – mezamorphic 2012-04-02 15:02:01

+1

@ user1107474這意味着,編譯器可以找到頭文件(* .h)中提供的聲明,但鏈接無法找到定義。 '聲明 - int Count();'<---你有這個地方,但缺少'定義 - 詮釋Count(){返回5; }' – 2012-04-02 21:17:23

2

需要分號(;

+0

謝謝,不要以爲你知道我現在得到的鏈接器問題? – mezamorphic 2012-04-02 15:06:45

+1

你是否重新鏈接WINAPI庫? – Attila 2012-04-02 15:14:19

5

您的類Something需要有一個終止分號。

class Something{ 

}; // missing 
相關問題