I’m writing a program for a lab called Robot. When I compile it, I get this set of errors:
Robot.cpp:43:13: error: expected unqualified-id before ‘double’
Robot.cpp:43:13: error: expected ‘)’ before ‘double’
The class is defined in the Robot.h header, and the code in the .cpp that’s causing the problem looks like this:
/*
* Name: Robot (constructor)
*
* Creates the robot with the given maximum speed.
*/
Robot( double maxSpd )
{
MAX_SPEED = maxSpd;
traveled = 0 ;
elapsed = 0 ;
x = 0 ;
y = 0 ;
}
I can’t figure out why the errors are there… and I also don’t know what that error even means. How would I solve it?
I’ve managed to recreate your errors.
First of all, that semicolon after the signature has to go. It’s declaring a function when you’re trying to define one.Robot(double maxSpd) {...} //no semicolonSecondlyFirst of all, since this is outside of your class, you need to qualify it:Next, since
MAX_SPEEDis a constant, you need to put it in a member initializer:Finally, you should move the rest of your assignments to the initializer list as well (not necessary, but good to do), keeping in mind that they should be listed in the order they are declared in the class definition: