Announcement

Collapse
No announcement yet.

Inheritance

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inheritance

    When you inherit one interface into another, I looks as if the instance variables *do not* get inherited. Is this the way it is supposed to work or am I missing something?

    I guess they will need to be replaced with globals in this case as far as I can see.
    Scott Slater
    Summit Computer Networks, Inc.
    www.summitcn.com

  • #2
    Originally posted by Scott Slater View Post
    When you inherit one interface into another, I looks as if the instance variables *do not* get inherited. Is this the way it is supposed to work or am I missing something?

    I guess they will need to be replaced with globals in this case as far as I can see.
    Your missing something.
    It would help if you provided just a wee bit of code.

    James

    Comment


    • #3
      Here is what I was experimenting with.

      Code:
      #Compile Exe
      #Dim All
      
      Class MyClass1
         Instance x As Long
         
         Interface MyInt1
            Inherit IUnknown
            Method DoubleX
               x *= 2
            End Method
            Property Get VarX() As Long
               Property = x
            End Property
            Property Set VarX(ByVal Invar As Long)
               x = Invar
            End Property
         End Interface
         
      End Class
      
      Class MyClass2
      
         Instance x As Long   ' If this line is *not* here, you get "Missing declaration X" compiler error...
                              ' If the line *is* there, then TrippleX does not work as expected...
         
         Interface MyInt2
            Inherit MyClass1, MyInt1
            Method TrippleX
               x *= 3
            End Method
         End Interface
         
      End Class
      
      Function PBMain () As Long
      
         Local MyObj As MyInt2
         
         MyObj = Class "MyClass2"
         
         MyObj.VarX = 5
         MyObj.TrippleX
         ? Format$(MyObj.VarX)   ' Result should be 15, but is not...
      
      End Function
      Scott Slater
      Summit Computer Networks, Inc.
      www.summitcn.com

      Comment


      • #4
        Use this:

        Code:
        Class MyClass2
        
           Interface MyInt2
              Inherit MyClass1, MyInt1
              Method TrippleX
                 ME.VarX = ME.Varx +3
              End Method
           End Interface
           
        End Class
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment


        • #5
          ...looks as if the instance variables *do not* get inherited.
          Actually, there essentially aren't any such things as interface variables. Interfaces are actually memory blocks containing pointers to functions.

          I actually myself haven't used the new PB compilers a great deal yet, but I stumbled over this issue at first too. In terms of other OOP languages inheritance of base class variables is supported to varying extents, for example in C++. However, the COM specification does not appear to allow for this, and PB likewise does not support it. Awhile back Kev Peel posted a work around for this which is pretty neat where properties instead of variables were used to transfer data between base and inheriting classes.

          Here is the link to Kev's post...

          http://www.powerbasic.com/support/pb...ad.php?t=38392
          Last edited by Fred Harris; 28 Sep 2008, 11:08 AM. Reason: add link
          Fred
          "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

          Comment


          • #6
            I see that there are work-arounds, but I guess my original question was if the "Instance" variables were inherited. It appears not in this case.
            Scott Slater
            Summit Computer Networks, Inc.
            www.summitcn.com

            Comment

            Working...
            X