Announcement

Collapse
No announcement yet.

Why is this a compile-time error?

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

  • Why is this a compile-time error?

    Using CC 5.01.0100 on Windows Vista.

    I'm having a problem getting the compiler to accept a fairly simple compound object reference, of this form:

    PrintTree oNode.LeftNode, sOrder
    Prototype: SUB PrintTree(BYVAL oNode as iface_Node, BYVAL sOrder AS STRING)

    However, the same compound reference (oNode.LeftNode) works with this subroutine prototype:

    PrintTree oNode.LeftNode
    Prototype: SUB PrintTree(BYVAL oNode as iface_Node)

    In the first case, I get a compiler error indicating that "Parameter mismatches definition", but the oNode.LeftNode expression should return a reference to iface_Node, which the subroutine is expecting.

    In the second case, as long as I have no additional parameters defined to pass to the subroutine, the same expression compiles (and works) just fine.

    Am I doing something wrong? The problem causes me to have to call the PrintTree routine (as defined in case 1 above) as follows:

    DIM oLeftNode as iface_Node

    oLeftNode = oNode.LeftNode
    PrintTree oLeftNode, sOrder

    This works, but results in unnecessarily complicated code, and requires an additional object reference to be defined and created.

    More complete (pastable) code examples follow:

    This code compiles (note: code doesn't do anything - I've removed all code unnecessary to demonstrate any problem except the compile-time exception).

    Code:
    #COMPILE EXE
    #DIM ALL
    
    CLASS Node
        INSTANCE pLeftNode AS iface_Node
        INSTANCE pRightNode AS iface_Node
        INSTANCE pValue AS LONG
        
        INTERFACE iface_Node
            INHERIT IUNKNOWN
            
            PROPERTY GET LeftNode AS iface_Node
                PROPERTY = pLeftNode
            END PROPERTY
            
            PROPERTY GET RightNode AS iface_Node
                PROPERTY = pRightNode
            END PROPERTY
            
            PROPERTY GET Value AS LONG
                PROPERTY = pValue
            END PROPERTY
            
        END INTERFACE
        
    END CLASS
    
    SUB PrintTree(BYVAL oNode AS iface_Node)
        
        IF ISNOTHING(oNode) THEN EXIT SUB
        PrintTree oNode.LeftNode
        STDOUT FORMAT$(oNode.Value)
        PrintTree oNode.RightNode
    
    END SUB
    
    FUNCTION PBMAIN () AS LONG
        DIM oNode AS iface_Node
        
        PrintTree oNode
        
    END FUNCTION
    This code does *not* compile:

    Code:
    #COMPILE EXE
    #DIM ALL
    
    CLASS Node
        INSTANCE pLeftNode AS iface_Node
        INSTANCE pRightNode AS iface_Node
        INSTANCE pValue AS LONG
        
        INTERFACE iface_Node
            INHERIT IUNKNOWN
            
            PROPERTY GET LeftNode AS iface_Node
                PROPERTY = pLeftNode
            END PROPERTY
            
            PROPERTY GET RightNode AS iface_Node
                PROPERTY = pRightNode
            END PROPERTY
            
            PROPERTY GET Value AS LONG
                PROPERTY = pValue
            END PROPERTY
            
        END INTERFACE
        
    END CLASS
    
    SUB PrintTree(BYVAL oNode AS iface_Node, BYVAL sOrder AS STRING)
        DIM i AS LONG
        
        IF ISNOTHING(oNode) THEN EXIT SUB
        
        FOR i = 1 TO LEN(sOrder)
            SELECT CASE MID$(sOrder,i,1)
                CASE "1"
                    PrintTree oNode.LeftNode, sOrder
                CASE "2"
                    STDOUT FORMAT$(oNode.Value)
                CASE "3"
                    PrintTree oNode.RightNode, sOrder
            END SELECT
        NEXT i
    END SUB
    
    FUNCTION PBMAIN () AS LONG
        DIM oNode AS iface_Node
        
        PrintTree oNode, "123" 'Print tree in pre-order sequence
        
        PrintTree oNode, "321" 'Print tree in post-order sequence
    
        PrintTree oNode, "213" 'Print tree in in-order sequence
    
    END FUNCTION
    Last edited by Patrick Mills; 7 Mar 2009, 12:00 PM. Reason: Removed another unnecessary bit of code from example 1
Working...
X