HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

vJass - static member & Interfaces

05-08-2007, 02:18 PM#1
zen87
Kay when i was learning vJass here, these few lines confused me, hope that some vJass experts can answer some question here
Quote:
Static members

An static member would just behave like a global variable inside struct syntax, just add the static keyword before the member syntax. There can be static arrays as well.

They might be useful in conjunction to methods.
what are the differnt between static methods and normal methods ? mm i mean something like this,
Collapse JASS:
struct somestruct
    real x = 1
    real y = 2
        method add takes nothing returns real
            return (.x+.y)
        endmethod

        static method add2 takes nothing returns real
            return (.x+.y)
        endmethod
endstruc
whats the different between the 2 methods ?

Quote:
Interfaces

Polymorphism is an OOP concept in which different object classes may have the same action, although the action is different, the action gets the same name. For example both an ant and a person run, but they are pretty different objects and the run action is implemented in different ways.

An interface is like a set of rules struct types follow and allow you to call actions of an struct without really knowing the exact type of the struct.

mmm this part i was totally lost, basically have no idea what interfaces is

thanks to all teachers that willing to teach a student here
05-08-2007, 02:24 PM#2
Vexorian
static methods are non-instance methos, they are just normal functions that can use private stuff in an struct.

Collapse JASS:

struct A

static integer i=0

static method q takes integer x returns nothing
   set A.i = A.i+x
endmethod

method r takes integer v returns nothing
    call A.q(v+4)
endmethod


endstruct


function B takes nothing returns nothing
    call A.q(56)
endfunction

05-08-2007, 04:25 PM#3
MaD[Lion]
interface is like a struct chooser if u put it that way. It choose to use a method from the correct struct depends on the parameter.
This is in case 2 structs has method of same name but different parameter.

this is like function overload in C++
05-08-2007, 06:20 PM#4
zen87
uh uh... i guess i somehow understand better... since i never learn C++ in the first place lol, jass was my first programming languague

thanks~