课程: Complete Guide to C++ Programming Foundations

免费学习该课程!

今天就开通帐号,24,100 门业界名师课程任您挑!

Overloading functions

Overloading functions

- [Instructor] In this exercise we'll explore the concept of function overloading, which allows us to define multiple functions with the same name, but different parameters or return types. Let's begin in line nine with a basic function called get speed. Which calculates the speed of a racer by dividing distance by time. Notice that this is an integer implementation. The two parameters are integers, and the return type is also an integer. The division operation calculates the quotient, which is an integer. Then the function is being used in line 16 where we call it to assign its return value to the integer variable speedInt. We are calculating the speed using 200 units of distance and four units of time. So if we run this, we'll get that the speed is 50. Indeed, the speed is 50. Let's go back to the code. Once again, we will approach the rest of this exercise in a top-down fashion where we start by calling the functions we want in the main function as if they were already implemented.…

内容