2012-03-13 130 views
0

嘿所有IM如果香港專業教育學院做了一個語法錯誤,但聽到香港專業教育學院做了一個類,當我嘗試編譯它得到這個錯誤不知道....編譯類與GCC

dining.h:7:1: error: unknown type name ‘class’ 
dining.h:7:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token 

它工作正常G ++,但我不得不使用gcc ...

這就是問題所在代碼..

#ifndef DINING_H 
#define DINING_H 

class DiningSet { 

    public: 
     DiningSet(); 
     ~DiningSet(); 
     void getSize(); // accepts X and Y dimentions of the table (in metres) 
     //void surfaceArea(int,int); // Calculates Surface Area of table (in square metres) 
     void numChairs(); // accepts number of chairs 
     void cushionColour(); // accepts a cushion colour 
     void woodType(); // accepts wood type 
     void priceComp(); // computes a price of set 
     void purchaseDet(); // displays details of purchase 
     void purchasePrice(); // displays price of purchace 

    private: 
     int X, Y; // Dimentions of table 
     float Surface; 
     int chairs; // Number of chairs 
     char colour; // colour of cushion (should be dynamic array) 
     char wood; 
     float totalPrice; 
}; 


#endif 
+0

請顯示您當前使用的命令行。 – 2012-03-13 05:20:44

回答

3

gcc默認爲您的程序編譯爲C.因爲它是一個C++程序,這是行不通的。使用-x c++標誌,或重命名文件以具有.C(案例很重要)或.cpp擴展名。

編輯:實際上,你可以使用一大堆文件擴展名來表示你的程序是C++。從this link

.CC,.cp,.CXX,的.cpp,.C++,.C

編輯2:您的評論下面讓我覺得你是想把這個頭文件在命令行上。不要這樣做。只需編譯源文件幷包含頭文件。

+0

你爲什麼要把你的頭文件放在命令行上? 'gcc file.cpp'會很好。如果你想使用'-x'標誌:'gcc -x C++ file.cpp'。 – 2012-03-13 05:19:07

+0

哦,我想我明白了。所以.h,我將用於g ++ isnt在gcc中無法識別\ – 2012-03-13 05:23:41

+0

我不知道這意味着什麼,但通常的做法不是單獨編譯頭文件。 – 2012-03-13 05:24:40