[Gambas-user] File opening dialog and one more question

Dmitrij Malkov dima.malkov.russia at ...626...
Sat Jan 7 10:09:54 CET 2012


I add a new class, child to CUnit. I named It "CUnitChild". It's code:
------------------------------------------
' Gambas class file

Inherits CUnit
------------------------------------------



And I add creation on object of this class in the middle of MMain:
------------------------------------------
' Gambas module file

Public Sub Main()
  Dim Unit1, Unit2, Unit3, Unit4 As CUnit 
  Dim i As Integer 'counter
  Dim aUnit As New CUnit[5] 'Array
  Dim Child1 As CUnitChild 'Inherited of CUnit
  
  CUnit.HowManyUnits()
  Unit1 = New CUnit
  Unit2 = New CUnit
  CUnit.HowManyUnits()
  Unit3 = New CUnit
  Unit4 = New CUnit
  CUnit.HowManyUnits()
  
  'trying to create and work with
  'child class of CUnit
  Child1 = New CUnitChild
  CUnitChild.HowManyUnits()
  Child1.PrintIdentification()
    
  'creation in a cycle
  For i = 1 To 100
    SubForCycleCreation()
  Next
  CUnit.HowManyUnits()
  
  'creation to an array
  For i = 0 To 4
    aUnit[i] = New CUnit
  Next
  CUnit.HowManyUnits()
  
  aUnit[0].PrintIdentification()
End

Public Sub SubForCycleCreation()
  Dim Unit5 As CUnit 
  Unit5 = New CUnit
End
------------------------------------------


The output is
------------------------------------------
There are 0 objects of class 'CUnit'
There are 2 objects of class 'CUnit'
There are 4 objects of class 'CUnit'
There are 5 objects of class 'CUnit'
Identity number of the object is 5
There are 105 objects of class 'CUnit'
There are 110 objects of class 'CUnit'
Identity number of the object is 106
------------------------------------------


Oh my God! "PRIVATE" in Gambas3 is the same, as "Protected" in C++, because
the existion of the object "Child1" changed the private data "Static Private
NumberOfUnits" of the class "CUnit". Maybe I am wrong.

How to rewrite constructor for a child class?
How to write and test destructors?

http://old.nabble.com/file/p33097604/OOP_3_STATIC-0.0.1.tar.gz
OOP_3_STATIC-0.0.1.tar.gz 
-- 
View this message in context: http://old.nabble.com/File-opening-dialog-and-one-more-question-tp33085420p33097604.html
Sent from the gambas-user mailing list archive at Nabble.com.





More information about the User mailing list