I have this code:
    
    
    type
        Console* = ref object of RootObj
        ViewportConsole* = ref object of Console
    
    method draw*[T](self: Console, engine: T) {.base.} =
        discard
    
    method draw*[T](self: ViewportConsole, engine: T) =
        # ...
    

I store the consoles in a sequence, and iterate through them, like this:
    
    
    var consoles: seq[Console]
    consoles.add(new(ViewportConsole))
    
    for console in consoles:
        console.draw(theEngineObject)
    

The last line should call the different **draw** method for different console 
types, but it seems to be only calling the base one. It only calls the 
ViewportConsole implementation if I explicitly cast **console**.

Is that a bug with generic methods, or am I doing this the wrong way? I was 
storing a reference to an **Engine** in the **Console** itself before, but 
**Engine** stores references to **Console** objects too, which was creating all 
sorts of problems related to cyclic dependencies, so I decided to use a generic 
method instead.

Reply via email to