2

Hello guys i had this error while i was compiling

error:'unisgned int vehicle::accelerate' is not a static member of 'class vehicle'

Any idea how to fix this?

Header file

class vehicle
{
    public:
    enum Switch
    {
     SWITCH_ON=0,
     SWITCH_OFF
                };
     vehicle();
    ~vehicle();

    bool powerSwitch(Switch );
    unsigned int accelerate(unsigned int );
    unsigned int decelerate(unsigned int );
    bool isMoving();
    unsigned int getSpeed();
    unsigned int setSpeed(unsigned int);

private:
unsigned int speed;
bool moving;
};

vehicle.cpp

unsigned int vehicle::accelerate(amount)
{

if(moving==true;){
speed+=amount;
 }

 return speed;

 }
4

3 回答 3

5

You are missing the type in the parameter list:

unsigned int vehicle::accelerate(unsigned int amount)
{
  .....
}
于 2012-10-30T08:45:58.720 回答
3

As you have declared:

unsigned int accelerate(unsigned int );

So you must implement:

unsigned int vehicle::accelerate(unsigned int amount)
{
  //...

The type needs to be given again at this point.

于 2012-10-30T08:46:12.880 回答
1

The error might be somewhere else, where you're trying to access the accelerate member not using the operator -> or ., but ::, apart from forgetting the type of the parameter

于 2012-10-30T08:46:00.833 回答