According to this page:
tads.org/t3doc/doc/sysman/multmeth.htm
There exists a means of making the determination of which overridden version of a method to call be a late decision that happens at runtime based on the type of the object actually being passed as a parameter.
However, upon trying it it seems the compiler is telling me that despite the name multi-method, this doesn’t actually work on methods (functions inside object classes). It only works on global functions, not on actual methods.
Is this true? Ideally I want to do a thing like this:
class Game: object
doTurnDaemon()
{
getCurPlayer().takeGameTurn(self);
}
;
class PokerGame: Game
;
class BlackjackGame: Game
;
class PokerActor: GameActor
takeGameTurn(PokerGame g)
{
}
;
class BlackjackActor: GameActor
takeGameTurn(BlackjackGame g)
{
}
;
cardSharpWilly: PokerActor, BlackjackActor
;
The idea is that when any Game object derived from Game, such as a PokerGame or Blackjackgame, runs the code seen above in doTurnDaemon(), on an actor who is multiply inherited from both PokerActor and BlackJackActor as in the example cardSharpWilly shown above, it gets the right version of the method takeGameTurn() because of the types listed in the function’s argument list.
But the above syntax does not work. It seems the compiler is insisting that doing a thing like this:
takeGameTurn(BlackjackGame g)
is illegal in a method. It’s only allowing it in a global function, so I have to implement this by putting the functions outside the classes like so:
class Game: object
doTurnDaemon()
{
takeGameTurn( getCurPlayer(), self);
}
;
class PokerActor: GameActor
;
takeGameTurn(PokerActor p, PokerGame g)
{
}
class BlackjackActor: GameActor
;
takeGameTurn(BlackjackActor p, BlackjackGame g)
{
}
Is this true? Or am I just not understanding the syntax error I’m getting and there is a way to make a multi-method an actual method inside a class?