What is the origin of the code ? This forum or a school assignment ?
I have seen it before, and the code seems to be taken from this: https://forum.arduino.cc/t/button-matrix-check-and-question-about-encoders/885387
You deleted that parts that are not used, but you deleted a little too much. As UKHeliBob already noticed, the "setup()" function is missing. And I think that a Joystick object needs to be declared and initialized.