Add tests with stateless/static function

This commit is contained in:
Lev
2021-06-13 11:48:00 -05:00
parent 3d53f23897
commit f89619dd37
2 changed files with 40 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,40 @@
class Car
{
public:
Car();
void accelerate();
static int whichIsFaster(Car carA, Car carB);
private:
float speed;
};
Car::Car() : speed(0.0f)
{
}
void Car::accelerate()
{
speed += 0.5f;
}
int Car::whichIsFaster(Car carA, Car carB)
{
if(carA.speed > carB.speed)
{
return 0;
}
return 1;
}
int main()
{
Car car1{};
car1.accelerate();
// state of car1 - speed is 1.5
Car car2;
car2.accelerate();
car2.accelerate();
// static functions don't need to remember or access the state of the function
Car::whichIsFaster(car1, car2);
}