C++ 用GCC编译类

C++ 用GCC编译类,c++,class,gcc,compilation,cc,C++,Class,Gcc,Compilation,Cc,嘿,我不确定我是否犯了一个语法错误,但是我创建了一个类,当我试图编译它的时候,得到了这个错误 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 clas

嘿,我不确定我是否犯了一个语法错误,但是我创建了一个类,当我试图编译它的时候,得到了这个错误

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
默认编译程序是C.,因为它是C++程序,这是行不通的。使用-x C++标志,或者重命名文件,以具有.c情况是重要的.CPP扩展。 <>编辑:实际上,你可以使用一组文件名扩展来指示你的程序是C++。发件人:

cc.c.cxx,cpP,C++,.c/p>


编辑2:你下面的评论让我觉得你试图把头文件放在命令行上。不要那样做。只需编译源文件并根据需要包含头文件。

为什么要将头文件放在命令行上?gcc file.cpp就可以了。如果你想使用-X标志:GCC -X C++文件。因此,我将用于g++的.h在gcc中不被认可\n我不知道这意味着什么,但通常的做法是不自己编译头文件。嗯,不确定我是否在这里说清楚了,因为我仍然有问题。。。很抱歉。我必须编译的文件是dinging.cpp和dinging.h。我必须使用CC编译器。所以我一直在做的就是这样编译。。cc dinging.cpp dinging.ht OP的问题明确排除了它。请显示您当前使用的命令行。