Announcement

Collapse
No announcement yet.

Converting C++ code to PB

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

  • Converting C++ code to PB

    Hi all,

    I need a primer on how to convert C++ to PB (as the subject instigates).

    How do you translate the "new" keyword in a statement like this:

    Code:
    xyz = new XYZ(hWnd, &r1);
    How do you define a class in PB, i.e. translate something like this:

    Code:
    class XYZ xxyyzz
    {
    	private:
    		CNullStorage    storage;
    		CMySite		site;
    
    	public:
    		HWND	hWnd;
    ...
    
    }


    ------------------
    Balt
    balt at inside dot net
    "It's not the end, not even the beginning of the end, but, it might be the end of the beginning!"

  • #2
    Balt,

    You can't translate classes to PB, because PB doesn't support classes.
    PB is, unlike C++, not an object-oriented programming language.

    You might however "simulate" using classes using ...

    Code:
    TYPE MyClass
       MyClassVar AS LONG
       MyClassVar2 AS STRING
     
    END TYPE
     
    FUNCTION MyClass_Function1(c AS MyClass PTR, param1 AS LONG) AS LONG
        LOCAL lRet AS LONG
     
        lRet = @c.MyClassVar * param1
     
        FUNCTION = lRet
    END FUNCTION
    
    ' this wouldn't probably work that way; it's just to show some concept how
    it might work
    FUNCTION MyClass_New() AS MyClass PTR
        LOCAL c AS MyClass PTR
        ' reserve memory for new instance
        
        c = VirtualAlloc(BYVAL %NULL, BYVAL SIZEOF(@c), %MEM_COMMIT)
    
        FUNCTION = @c
    END FUNCTION
    
    FUNCTION MyClass_Dispose(c AS MyClass PTR)
        VirtualFree BYVAL c, %MEM_RELEASE
    END FUNCTION
    This would simulate the following VB.NET class:

    Code:
    Class MyClass
        Public MyClassVar As Integer
        Public MyClassVar2 As Integer
     
        Public Function MyClassFunction1(param1 As Integer) As Integer
            Return MyClassVar * param1
        End Function
     
    End Class
    To access class members ...
    Code:
    FUNCTION PBMAIN AS LONG
        LoCAL c AS MyClass PTR
     
        c = MyClass_New()
     
        @c.MyClassVar = 500
     
        @c.MyClassVar2 = MyClass_Function1(@c, 100)
     
        MyClass_Dispose c
     
    END FUNCTION
    I hope that explains a bit ...

    Regards

    PS: You should also know, that languages like VB.NET, C++ etc., do nothing
    else than "convert" the object-oriented code to something like my PB code.
    Don't forget: Objects are not natively supported by the processor!
    ------------------




    [This message has been edited by Lothar Pink (edited August 02, 2004).]

    Comment


    • #3
      Another twist on OO programming:

      http://www.allbasiccode.com/newsite/abc.cgi?ACT=DQ

      Search on "oop.bas".


      ------------------
      Regards
      ----------------------
      Robert DeBolt
      mailto:[email protected][email protected]</A>
      Regards,
      Bob

      Comment

      Working...
      X