class car {
int speed;
double position;
public:
car(int v,double d);
int getspeed();
};
int car::getspeed() {
return speed;
}
car::car(
This constructor doesn't work
car::car(int speed, double position){
speed=speed;
position=position;
}
because it assigns the parameters to themselves.
This version does work because of the slightly odd scoping rules of a class
car::car(int speed, double position) : speed(speed), position(position)
{ }