In this video, we’re going to discuss two functions that we wrote for you. They’re really
wrappers. They wrap the logic needed to connect C++ to Python. The first function is called call
procedure. As you notice, it returns nothing. You pass to it a string. We’ll talk about that string
in a few minutes. The other function is declared twice. So we can see that it’s declared here
and it’s declared here.
The first declaration you pass a string and then string while the other declaration you pass a
string then an integer. This is called function overloading when you declare the same function
twice but you change the parameter types.
So how do we use them? Well if I want to call a function that does nothing other than—sorry.
When we want to call a function that returns nothing but it does some work on the Python
site, we would use call procedure. So if we look at print something, let’s go to the Python code.
Here we go. Print something. Here we go. Print something simply prints a message, but it
doesn’t return anything. So let’s comment this line and this line and let’s run it. And here you
go. It just says hello from Python. That’s what that procedure does.
If you want to call a function that returns an integer, then we would use this function. And
when we want to pass a string, we would pass the function name in Python and the string
parameter. So we’re passing the word house to the function print me. So let’s look at print me.
Here it is. V is going to receive the word house. This is going to say, you’ve sent me house
because V has the word house. And then, it’s going to return 100. I just made up this number.
You can return whatever you want.
So this 100 will replace this code and C++ will print 100. Let’s run it. Here it is. You sent me
house and then C++ printed whatever got returned that was returned from the Python code.
Finally, if you want to call a function but instead of passing a string you want to pass an
integer, so you can still use the same function. That’s why it’s overloaded as you can see. It’s
declared here twice, one with two strings, one with a string then an integer. Then you would
just call our function the name of the function in Python and you would send a number.
So this is a mult, it’s a function called mult. Let’s look at it. Oh we don’t have mult. OK. So
square value. Good. Let’s go to it. That’s good actually. I had one before so it’s called mult. So
square value, 10. I passed 10. Let’s look at this. 10 will be here in V. This will return 10 times
10. So let’s run it. 10 times 10 is 100. OK?
So just to note, just to clarify so there’s no confusion, why did it display 102 times? Because
this function return 100 really. It’s just random. So let’s just return 1 here. This function, I just
wanted to demonstrate that it can return a value. So let’s return 1 here. And here it will just
multiply. And instead of 10 let’s pass a 5 for example. If we run it, see? That function, this 1,
gave us a 1. The other call gave us 25.