moto
moto

Reputation: 21

Compilation error: `Class' does not name a type

I have a pretty simple class called simulator in simulator.h

#include <iostream.h>
#include <stdlib.h>

Class Simulator {

   private:  
    short int startFloor;  
    short int destFloor;  
   public:  
        void setFloors();  
        void getFloors(short int &, short int &);  

};  

Now when I compile it, I get this error:
simulator.h:4: error: `Class' does not name a type

What have I got wrong here?

Upvotes: 2

Views: 3344

Answers (6)

Justin Niessner
Justin Niessner

Reputation: 245429

You need to make Class lowercase (and should probably stop using the deprecated iostream.h header):

#include <iostream>
#include <cstdlib>

class Simulator {
    // Stuff here
}

Upvotes: 5

highBandWidth
highBandWidth

Reputation: 17321

When you write

Class Simulator {

the compiler thinks 'Class' is a type like int, float or a user-defined class, struct or typedef.

The keyword used to define classes in c++ (as other answers also mention) is 'class'. Note also, the new header file names are iostream (since its a standard c++ header), and cstdlib (since its actually a c header).

Hence it should be

#include <iostream>
#include <cstdlib>

class Simulator {

   private:  
    short int startFloor;  
    short int destFloor;  
   public:  
        void setFloors();  
        void getFloors(short int &, short int &);  

}; 

Upvotes: 1

dgnorton
dgnorton

Reputation: 2247

Make the 'C' a 'c' in the word Class. Has to be lower case.

Upvotes: 0

Arun
Arun

Reputation: 20383

It must be lower case class.

It must be

#include <iostream>

Upvotes: 1

dagnelies
dagnelies

Reputation: 5321

should be lowercase "class" instead of "Class" ;)

Upvotes: 1

Vasilis Lourdas
Vasilis Lourdas

Reputation: 1179

I think it's lowercase class.

Upvotes: 1

Related Questions