Revision history for TutBeginnersGuideToTypesAsObjects2


Revision [22207]

Last edited on 2018-02-10 13:40:16 by JeffMarshall [escape camel-case words]
Additions:
You must remember to call Delete, or Delete[] for any memory allocated with New, or you will cause a memory leak, just like the way you must rememeber to call ""DeAllocate"" for any memory you allocate with the Allocate function.
Deletions:
You must remember to call Delete, or Delete[] for any memory allocated with New, or you will cause a memory leak, just like the way you must rememeber to call DeAllocate for any memory you allocate with the Allocate function.


Revision [22205]

Edited on 2018-02-10 13:34:55 by JeffMarshall [escape camel-case words]
Additions:
BAR::BAR(int) - The constructor taking an integer argument (note there is no special symbol to denote ""ByVal"", as this is the default passing method in C/""C++"")
Deletions:
BAR::BAR(int) - The constructor taking an integer argument (note there is no special symbol to denote ByVal, as this is the default passing method in C/""C++"")


Revision [22203]

Edited on 2018-02-10 13:32:13 by JeffMarshall [escape camel-case words]
Additions:
**Passing objects to functions ""ByVal""**
The idea of deep and shallow copies also applies to passing an object to a function by value. When you pass a reference to an object (""ByRef""), you can modify the object, and these modifications will persist, however you can also pass by value, which will mean you can modify it without the changes persisting outside of the function. When an object is passed by value to a function, a new copy is created, and if that object has a copy constructor, then this is invoked, if it doesn't, then the hidden shallow copy is performed. Once the function ends, the objects destructor is called.
New and delete are special operators for dynamically allocating memory, then destroying it. Because it is used with dynamic memory, it is used with pointers. In all the examples up until now, we just used Dim to create our objects, this will create them on the stack, but by using new we can create them dynamically, which can allow more flexibility, just like using Allocate/""DeAllocate"" with normal memory. Another important thing about new, is that you don't need to check if the pointer is NULL after new, like you would if you did allocate. If new fails, it causes an exception, which will end the program. In later versions of FreeBASIC, it is likely that some kind of try..catch mechanism will be created to allow better exception handling, but as of the time of writing, this is not yet implemented.
Deletions:
**Passing objects to functions ByVal**
The idea of deep and shallow copies also applies to passing an object to a function by value. When you pass a reference to an object (ByRef), you can modify the object, and these modifications will persist, however you can also pass by value, which will mean you can modify it without the changes persisting outside of the function. When an object is passed by value to a function, a new copy is created, and if that object has a copy constructor, then this is invoked, if it doesn't, then the hidden shallow copy is performed. Once the function ends, the objects destructor is called.
New and delete are special operators for dynamically allocating memory, then destroying it. Because it is used with dynamic memory, it is used with pointers. In all the examples up until now, we just used Dim to create our objects, this will create them on the stack, but by using new we can create them dynamically, which can allow more flexibility, just like using Allocate/DeAllocate with normal memory. Another important thing about new, is that you don't need to check if the pointer is NULL after new, like you would if you did allocate. If new fails, it causes an exception, which will end the program. In later versions of FreeBASIC, it is likely that some kind of try..catch mechanism will be created to allow better exception handling, but as of the time of writing, this is not yet implemented.


Revision [22184]

Edited on 2018-02-07 00:45:36 by sancho3 [escape camel-case words]
Additions:
//Last Reviewed by ""Sancho3"" on February 06, 2018//


Revision [12141]

The oldest known version of this page was created on 2008-01-05 15:52:28 by ElSairon [escape camel-case words]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode