Hi all, Please see this code. I somehow managed to access base class member 
from child class, by giving the base as parameter in child's ctor. See this 
code. But i cant access the base class member from instantiated child variable. 
    
    
    type
        BaseWindow = ref object of RootObj
            title : string
            width : int
            height : int
            windowCount : int
            windowList : seq[int]
        
        ChildWindow = object of BaseWindow
            handle : int
    
    proc NewBaseWindow*(title : string = "My New window") : BaseWindow =
        result = new BaseWindow
        result.title = title
        result.width = 800
        result.height = 600
        result.windowCount = 0
        result.windowList = @[]
    
    # Child class ctor is taking base class as param. Without this, i cant 
access base members.
    # Please tell me that, is there a better way to do this.
    proc NewChildWindow*(base : BaseWindow) : ChildWindow =
        base.windowCount.inc()  # Want to modify base class member
        base.windowList.add(base.windowCount) # Want to modify base class member
        echo "Created a Window"
        echo "Title = ", base.title # Want to access base class member
        echo "Width = ", base.width # Want to access base class member
        echo "Height = ", base.height # Want to access base class member
    
    var bw = NewBaseWindow()
    var cw = NewChildWindow(bw)
    echo cw.windowList.len  # Want to access base class member, but can't. 
Please help.
    
    
    Run

Reply via email to