Static Functions
Posted
#1
(In Topic #293)
Trainee
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);
Posted
Guru

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

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.
Ced
.... and carry a big stick!
1 guest and 0 members have just viewed this.


