Static Functions

Post Reply
Posts: 1
Joined: Saturday 05th January 2019 12:05am

Static Functions

Post by ShaneP » Friday 12th July 2019 11:10am

Are we able to do this in gambas

if we have a class called Vector with a function "subtract" can we then do

Vector mouse = new Vector(mouseX,mouseY);
Vector dir = Vector.subtract(mouse,location);

User avatar
Site Admin
Posts: 485
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Static Functions

Post by cogier » Friday 12th July 2019 1:49pm

Hi ShaneP and welcome to the forum.

Can you explain exactly what you want to achive. I'm not sure I understand the question that well.

User avatar
Posts: 119
Joined: Thursday 21st February 2019 5:02pm
Location: The Mitten State

Re: Static Functions

Post by Cedron » Friday 12th July 2019 7:07pm

Your example is chock full of reserved (or previously used) words, so I'm not going to manipulate it into proper syntax.

The answer is "Yes, you can"

Static subs can only reference static variables. Static variables are shared across all instances. A static sub can create an instance of the class and return it. A static sub can also take an instance as an argument. Of course, the same is true for non-static (instance methods) too.

It shouldn't be too difficult for you to whip up an example project to demonstrate this. If you encounter any trouble, just ask for help.

.... and carry a big stick!

Post Reply