-1

Hey all im not sure if ive made a syntactical error hear but ive made a class and get this error when i try to compile it....

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

it works fine with g++ but i have to use gcc...

this is the problem code..

#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
Carl Norum
  • 219,201
  • 40
  • 422
  • 469
Daniel Del Core
  • 3,071
  • 13
  • 38
  • 52

1 Answers1

3

gcc defaults to compiling your program as C. Since it's a C++ program, that's not going to work. Use the -x c++ flag, or rename your file to have a .C (case is important) or .cpp extension.

Edit: actually, you can use a whole bunch of filename extensions to indicate that your program is C++. From this link:

.cc, .cp, .cxx, .cpp, .c++, .C

Edit 2: Your comment below makes me think you're trying to put the header file on the command line. Don't do that. Just compile source files and include the headers as necessary.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • Why are you putting your header file on the command line? `gcc file.cpp` would be fine. If you want to use the `-x` flag: `gcc -x c++ file.cpp`. – Carl Norum Mar 13 '12 at 05:19
  • ohk i think i understand. so the .h that i would use for g++ isnt recognised in gcc\ – Daniel Del Core Mar 13 '12 at 05:23
  • I don't know what that means, but normal practice is not to compiler header files on their own. – Carl Norum Mar 13 '12 at 05:24
  • hmm not sure if ive made my self clear here because im still having problems... sorry about this. my files i have to compile are dining.cpp and dining.h. i have to use CC compiler. so what ive been doing is compiling like this.. cc dining.cpp dining.h – Daniel Del Core Mar 13 '12 at 05:30
  • 1
    The OP's question specifically excludes it. – Carl Norum Mar 13 '12 at 14:52