Hello everyone, I am writing a code for a class that needs to have a constructor that is the starting values. For some reason when i have parameters in constructor I get an error and I do not know why. If anyone can tell me how to fix this i would appreciate it.
You are missing a declaration of that constructor in your class definition.
So on line 15, you need:
Rover(int x,int y,string direct, int spd);
But the parameters aren't needed: you ask for input then assign values to member variables.
Normally a constructor like that would have the parameters, not ask for input (do that elsewhere), and set the member variables via a member initialisation list:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Rover::Rover(const std::string& name, // make sure to init all member variables
constint x, // parameters are const if we aren't changing them
constint y,
const std::string& direct, // pass containers by reference
constint spd)
: // colon introduces member initialisation list
name(name),
xpos(x), // direct initialisation more efficient than assignment
ypos(y), // assignment causes construction of temporaries & copying
direction(direct), // then direct initialisation
speed(spd)
{
// do validation here
}