somGetMethodToken
Appearance
This method returns a method access token for static method. Not generally overridden.
For backward compatibility, this method does not take an Environment parameter.
- Original Class
- SOMClass
Syntax
somMToken somGetMethodToken (SOMClass receiver, somId methodId)
Parameters
- receiver (SOMClass)
- A pointer to a SOMClass object.
- methodId (somId)
- A somId identifying a method.
Return Code
- rc (somMToken)
- Returns a somMToken method access token.
Remarks
This method returns a method access token for a static method with the specified id that was introduced by the receiver class or an ancestor of the receiver class. This method token can be passed to the somResolve function (or one of the other offset-based method resolution functions) to select a method procedure pointer from a method table of an object whose class is the same as, or is derived from the class that introduced the method.
The example below assumes that the class Animal introduces the method setSound.
Example Code
#include < > main() { somMToken tok; Animal myAnimal; somTD_Animal_setSound methodPtr; /* use typedef from animal.h */ Environment *ev = somGetGlobalEnvironment(); myAnimal = AnimalNew(); /* next 3 lines equivalent to _setSound(myAnimal, ev, "Roar!!!"); */ tok = _ somGetMethodToken(_Animal, somIdFromString("setSound")); methodPtr = (somTD_Animal_setSound)somResolve(myAnimal, tok); methodPtr(myAnimal, ev, "Roar!!!"); _display(myAnimal, ev); _somFree(myAnimal); }