
Here is my attempt to experiment with OOPS with help from David L Morris
and Petr Schreiber jr.
These examples come from Teach Yourself C++ by Al Stevens.
Code:
REM Ex-07-01-DavidLMorris.bas #COMPILE EXE #DIM ALL #INCLUDE "Ex-07-01.inc" FUNCTION PBMAIN () AS LONG LOCAL thiscube AS Cube LOCAL thiscube2 AS Cube Cube__Cube(thiscube,7,8,9) PRINT "volume = " + STR$(Cube__volume(thiscube)) Cube___Cube(thiscube) PRINT Cube__Cube(thiscube2,27,28,29) PRINT "volume = " + STR$(Cube__volume(thiscube2)) Cube___Cube(thiscube2) WAITKEY$ END FUNCTION
Code:
' ---------- a Cube class ' Ex-07-01.inc MACRO CLASS=TYPE '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CLASS Cube m_lheight AS LONG m_lwidth AS LONG m_ldepth AS LONG 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 '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enjoy!


Comment