A non-static class method, such as fun
, is always called on an instance of its class. You need an instance of cls to call fun. You may get that instance in one of the following ways:
- By creating a
cls
object inside the body of fun
.
- By passing a
cls
object (or a reference to it, or a pointer to it) as a parameter to fun (involves changing the signature of fun
).
- By creating a global variable of type
cls
(I strongly discourage this option).
Alternatively, fun
might be declared as static, provided that it does not use any filed of the cls class. In that case, you could invoke it without an associated instance of cls, with the following instruction: cls::fun()
.