
Hi. I am toying with the implementation of OOPS in PowerBASIC.
I submit the following code for your suggestions and criticisms:
They are patterned after examples in the book "Teach yourself C++"
by Al Stevens.
Code:
Rem Ex-07-01.bas Rem PBCC 4.04.0042 #Compile Exe #Dim All #Include "Ex-07-01.inc" Function PBMain () As Long Local lresult As Long Local thiscube As Cube Constructor(thiscube,7,8,9) Volume(thiscube) Print "volume = " + Str$(lresult) Destructor(thiscube) WaitKey$ End Function
Code:
Rem ---------- a Cube class Rem Ex-07-01.inc Rem PBCC 4.04.0042 Macro CLASS=Type Macro Constructor(mycube, lht,lwd,ldp) mycube.m__Cube = CodePtr(Cube__Cube) ' Constructor. mycube.m___Cube = CodePtr(Cube___Cube) ' Destructor. mycube.m__volume = CodePtr(Cube__volume) ' Volume. Call Dword mycube.m__Cube Using Cube__Cube(mycube, lht,lwd,ldp) End Macro Macro Destructor(mycube) Call Dword mycube.m___Cube Using Cube___Cube(mycube) End Macro Macro volume(mycube) ' Corrected 07-22-08 ' Call Dword thiscube.m__volume Using Cube__volume(thiscube) To lresult Call Dword mycube.m__volume Using Cube__volume(mycube) To lresult End Macro '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CLASS Cube m_lheight As Long m_lwidth As Long m_ldepth As Long m__cube As Dword ' Constructor. m___cube As Dword ' Destructor. m__volume As Dword ' Member function (compute volume). End CLASS '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Constructor. Sub Cube__Cube(mycube As Cube, lheight As Long, lwidth As Long, ldepth As Long) Print "Constructor" mycube.m_lheight = lheight mycube.m_lwidth = lwidth mycube.m_ldepth = ldepth End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Destructor. Sub Cube___Cube(mycube As Cube) Print "Destructor" End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Member function (compute volume). Function Cube__volume(mycube As Cube) As Long Print "Cube__volume" Function = mycube.m_lheight * mycube.m_lwidth * mycube.m_ldepth End Function '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Comment