Revision history for KeyPgExtends


Revision [22002]

Last edited on 2017-11-21 01:11:05 by JeffMarshall [fix page link name case]
Additions:
User-defined types that extend another type will include the base type structure at their beginning, and their size as reported by ##[[KeyPgSizeof|sizeof()]]## is the sum of their base type's size plus the size needed for any regular data fields (non-static data fields). Since the inherited members make sure that the structure is not empty, a derived type is not required to have regular data fields of its own.
Deletions:
User-defined types that extend another type will include the base type structure at their beginning, and their size as reported by ##[[KeyPgSizeOf|sizeof()]]## is the sum of their base type's size plus the size needed for any regular data fields (non-static data fields). Since the inherited members make sure that the structure is not empty, a derived type is not required to have regular data fields of its own.


Revision [21892]

Edited on 2017-09-08 02:56:57 by fxm [wording]
Additions:
**Note:** UDT pointer can only be cast to pointer types of "widened compatibility" (up or even down in the inheritance hierarchy), or to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]##. Otherwise, cast to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]## first (or to ##[[KeyPgObject|Object]] [[KeyPgPtr|Ptr]]## first if both types are directly or indirectly derived from ##[[KeyPgObject|Object]]##).
Deletions:
**Note:** UDT pointer can only be cast to pointer types of "widened compatibility" (up or even down in the inheritance hierarchy), or to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]##. Otherwise, cast to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]## first (or to ##[[KeyPgObject|Object]] [[KeyPgPtr|Ptr]]## if both types are directly or indirectly derived from ##[[KeyPgObject|Object]]##).


Revision [21891]

Edited on 2017-09-05 15:46:39 by fxm [wording]
Additions:
**Note:** UDT pointer can only be cast to pointer types of "widened compatibility" (up or even down in the inheritance hierarchy), or to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]##. Otherwise, cast to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]## first (or to ##[[KeyPgObject|Object]] [[KeyPgPtr|Ptr]]## if both types are directly or indirectly derived from ##[[KeyPgObject|Object]]##).
Deletions:
**Note:** UDT pointer can only be cast to pointer types of "widened compatibility" (up or even down in the inheritance hierarchy) or to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]##. Otherwise, cast to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]## first (or to ##[[KeyPgObject|Object]] [[KeyPgPtr|Ptr]]## if both types are directly or indirectly derived from ##[[KeyPgObject|Object]]##).


Revision [21887]

Edited on 2017-09-01 16:57:57 by fxm [wording]
Additions:
**Note:** UDT pointer can only be cast to pointer types of "widened compatibility" (up or even down in the inheritance hierarchy) or to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]##. Otherwise, cast to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]## first (or to ##[[KeyPgObject|Object]] [[KeyPgPtr|Ptr]]## if both types are directly or indirectly derived from ##[[KeyPgObject|Object]]##).
Deletions:
**Note:** UDT pointer can only be cast to pointer types of "widened compatibility" (up or even down in the inheritance hierarchy) or ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]##. Otherwise, cast to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]## first (or ##[[KeyPgObject|Object]] [[KeyPgPtr|Ptr]]## if both types are directly or indirectly derived from ##[[KeyPgObject|Object]]##).


Revision [21886]

Edited on 2017-09-01 16:50:26 by fxm [wording]
Additions:
**Note:** UDT pointer can only be cast to pointer types of "widened compatibility" (up or even down in the inheritance hierarchy) or ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]##. Otherwise, cast to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]## first (or ##[[KeyPgObject|Object]] [[KeyPgPtr|Ptr]]## if both types are directly or indirectly derived from ##[[KeyPgObject|Object]]##).
Deletions:
**Note:** UDT pointer can only be casted to "widened compatible" pointer types (up/down the inheritance hierarchy on the branch) or ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]##. Otherwise, cast to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]## first (or ##[[KeyPgObject|Object]] [[KeyPgPtr|Ptr]]## if both types are directly or indirectly derived from ##[[KeyPgObject|Object]]##).


Revision [21885]

Edited on 2017-09-01 07:19:25 by fxm [wording]
Additions:
**Note:** UDT pointer can only be casted to "widened compatible" pointer types (up/down the inheritance hierarchy on the branch) or ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]##. Otherwise, cast to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]## first (or ##[[KeyPgObject|Object]] [[KeyPgPtr|Ptr]]## if both types are directly or indirectly derived from ##[[KeyPgObject|Object]]##).
Deletions:
**Note:** UDT pointer can only be casted to "widened compatible" pointer types (up/down the inheritance hierarchy on the branch) or ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]##. Otherwise, cast to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]## first (or ##[[KeyPgObject|Object]] [[KeyPgPtr|Ptr]]## if both are directly or indirectly derived from ##[[KeyPgObject|Object]]##).


Revision [21884]

Edited on 2017-09-01 06:56:03 by fxm [wording]
Additions:
**Note:** UDT pointer can only be casted to "widened compatible" pointer types (up/down the inheritance hierarchy on the branch) or ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]##. Otherwise, cast to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]## first (or ##[[KeyPgObject|Object]] [[KeyPgPtr|Ptr]]## if both are directly or indirectly derived from ##[[KeyPgObject|Object]]##).
Deletions:
**Note:** Derived UDT pointer can only be casted to "compatible" pointer types (up/down the inheritance hierarchy) or ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]##. Otherwise, cast to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]## first.


Revision [21571]

Edited on 2016-08-21 17:44:08 by fxm [Define a "regular" member and use "regular" wisely]
Additions:
##**Extends**## declares ##//typename//## to be derived from ##//base_typename//##. The derived user-defined type, ##//typename//##, inherits fields and methods of the ##//base_typename//## base type. ##//typename//## objects may be used in place of ##//base_typename//## objects. Fields and methods inherited from ##//base_typename//## will be implicitly accessible like members of ##//typename//##.
However, a member will shadow an inherited member if they have the same identifier. The ##[[KeyPgBase|Base (member access)]]## keyword can be used to explicitly access members of the base type shadowed by local members.
User-defined types that extend another type will include the base type structure at their beginning, and their size as reported by ##[[KeyPgSizeOf|sizeof()]]## is the sum of their base type's size plus the size needed for any regular data fields (non-static data fields). Since the inherited members make sure that the structure is not empty, a derived type is not required to have regular data fields of its own.
Deletions:
##**Extends**## declares ##//typename//## to be derived from ##//base_typename//##. The derived user-defined type, ##//typename//##, inherits fields and methods of the ##//base_typename//## base type. ##//typename//## objects may be used in place of ##//base_typename//## objects. Fields and methods inherited from ##//base_typename//## will be implicitly accessible like regular members of ##//typename//##.
However, a regular member will shadow an inherited member if they have the same identifier. The ##[[KeyPgBase|Base (member access)]]## keyword can be used to explicitly access members of the base type shadowed by local members.
User-defined types that extend another type will include the base type structure at their beginning, and their size as reported by ##[[KeyPgSizeOf|sizeof()]]## is the sum of their base type's size plus the size needed for any regular members. Since the inherited members make sure that the structure is not empty, a derived type is not required to have regular members of its own.


Revision [20233]

Edited on 2016-02-10 16:00:12 by DkLwikki [Update link format]
Additions:
[[KeyPgType|Type]]|[[KeyPgUnion|Union]] //typename// **Extends** //base_typename//
End [[KeyPgType|Type]]|[[KeyPgUnion|Union]]
However, a regular member will shadow an inherited member if they have the same identifier. The ##[[KeyPgBase|Base (member access)]]## keyword can be used to explicitly access members of the base type shadowed by local members.
User-defined types that extend another type will include the base type structure at their beginning, and their size as reported by ##[[KeyPgSizeOf|sizeof()]]## is the sum of their base type's size plus the size needed for any regular members. Since the inherited members make sure that the structure is not empty, a derived type is not required to have regular members of its own.
In ##//typename//## (the derived user-defined type), the fields can share the same memory space than the ##//base_typename//## only if ##//typename//## is a ##[[KeyPgUnion|Union]]##. Here it does not matter whether ##//base_typename//## is a ##[[KeyPgUnion|Union]]## or not.
If only ##//base_typename//## is a ##[[KeyPgUnion|Union]]##, then it will not be affected by fields from ##//typename//## (the derived user-defined type).
As a ##[[KeyPgUnion|Union]]## is not allowed to have complex fields (i.e. user-defined types with constructor/destructor, or dynamic strings), a derived ##[[KeyPgUnion|Union]]## cannot be allowed to have (contain) a complex ##//base_typename//##.
The ##[[KeyPgBaseInit|Base (initializer)]]## keyword can be used at the top of constructor of derived user-defined type. It allows to specify an initializer or constructor call for the base type.
Extending the built-in ##[[KeyPgObject|Object]]## type allows a user-defined type to be used with ##[[KeyPgOpIs|Operator Is]]## to perform run-time type checks, to support ##[[KeyPgVirtual|Virtual]]## and ##[[KeyPgAbstract|Abstract]]## methods, and to use the ##[[KeyPgOverride|Override]]## method attribute.
**Note:** Derived UDT pointer can only be casted to "compatible" pointer types (up/down the inheritance hierarchy) or ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]##. Otherwise, cast to ##[[KeyPgAny|Any]] [[KeyPgPtr|Ptr]]## first.
**Warning:** Before fbc version 0.24, these five keywords dedicated to inheritance ##**Extends**##, ##[[KeyPgBase|Base (member access)]]##, ##[[KeyPgBaseInit|Base (initializer)]]##, ##[[KeyPgObject|Object]]## and ##[[KeyPgOpIs|Operator Is]]## were not supported. Three new keywords ##[[KeyPgVirtual|Virtual]]##, ##[[KeyPgAbstract|Abstract]]##, and ##[[KeyPgOverride|Override]]## come with fbc version 0.90.
' which must be overriden
' body which can be overriden
' 'Override' to check if the function is
' well an override
' 'Override' to check if the destructor is well an override
' override
' override
- Not available in the //[[CompilerOptlang|-lang qb]]// dialect unless referenced with the alias ##**""__Extends""**##.
- ##[[KeyPgType|Type]]##
- ##[[KeyPgUnion|Union]]##
- ##[[KeyPgBaseInit|Base (initializer)]]##
- ##[[KeyPgBase|Base (member access)]]##
- ##[[KeyPgObject|Object]]##
- ##[[KeyPgOpIs|Operator Is]]##
- ##[[KeyPgVirtual|Virtual]]##
- ##[[KeyPgAbstract|Abstract]]##
- ##[[KeyPgOverride|Override]]##
Deletions:
[[KeyPgType Type]]|[[KeyPgUnion Union]] //typename// **Extends** //base_typename//
End [[KeyPgType Type]]|[[KeyPgUnion Union]]
However, a regular member will shadow an inherited member if they have the same identifier. The ##[[KeyPgBase Base (member access)]]## keyword can be used to explicitly access members of the base type shadowed by local members.
User-defined types that extend another type will include the base type structure at their beginning, and their size as reported by ##[[KeyPgSizeOf sizeof()]]## is the sum of their base type's size plus the size needed for any regular members. Since the inherited members make sure that the structure is not empty, a derived type is not required to have regular members of its own.
In ##//typename//## (the derived user-defined type), the fields can share the same memory space than the ##//base_typename//## only if ##//typename//## is a ##[[KeyPgUnion Union]]##. Here it does not matter whether ##//base_typename//## is a ##[[KeyPgUnion Union]]## or not.
If only ##//base_typename//## is a ##[[KeyPgUnion Union]]##, then it will not be affected by fields from ##//typename//## (the derived user-defined type).
As a ##[[KeyPgUnion Union]]## is not allowed to have complex fields (i.e. user-defined types with constructor/destructor, or dynamic strings), a derived ##[[KeyPgUnion Union]]## cannot be allowed to have (contain) a complex ##//base_typename//##.
The ##[[KeyPgBaseInit Base (initializer)]]## keyword can be used at the top of constructor of derived user-defined type. It allows to specify an initializer or constructor call for the base type.
Extending the built-in ##[[KeyPgObject Object]]## type allows a user-defined type to be used with ##[[KeyPgOpIs Operator Is]]## to perform run-time type checks, to support ##[[KeyPgVirtual Virtual]]## and ##[[KeyPgAbstract Abstract]]## methods, and to use the ##[[KeyPgOverride Override]]## method attribute.
**Note:** Derived UDT pointer can only be casted to "compatible" pointer types (up/down the inheritance hierarchy) or ##[[KeyPgAny Any]] [[KeyPgPtr Ptr]]##. Otherwise, cast to ##[[KeyPgAny Any]] [[KeyPgPtr Ptr]]## first.
**Warning:** Before fbc version 0.24, these five keywords dedicated to inheritance ##**Extends**##, ##[[KeyPgBase Base (member access)]]##, ##[[KeyPgBaseInit Base (initializer)]]##, ##[[KeyPgObject Object]]## and ##[[KeyPgOpIs Operator Is]]## were not supported. Three new keywords ##[[KeyPgVirtual Virtual]]##, ##[[KeyPgAbstract Abstract]]##, and ##[[KeyPgOverride Override]]## come with fbc version 0.90.
' which must be overriden
' body which can be overriden
' 'Override' to check if the function is
' well an override
' 'Override' to check if the destructor is well an override
' override
' override
- Not available in the //[[CompilerOptlang -lang qb]]// dialect unless referenced with the alias ##**""__Extends""**##.
- ##[[KeyPgType Type]]##
- ##[[KeyPgUnion Union]]##
- ##[[KeyPgBaseInit Base (initializer)]]##
- ##[[KeyPgBase Base (member access)]]##
- ##[[KeyPgObject Object]]##
- ##[[KeyPgOpIs Operator Is]]##
- ##[[KeyPgVirtual Virtual]]##
- ##[[KeyPgAbstract Abstract]]##
- ##[[KeyPgOverride Override]]##


Revision [17657]

Edited on 2015-05-29 01:51:11 by FxMwikki [Added some complements when using Union]
Additions:
As a ##[[KeyPgUnion Union]]## is not allowed to have complex fields (i.e. user-defined types with constructor/destructor, or dynamic strings), a derived ##[[KeyPgUnion Union]]## cannot be allowed to have (contain) a complex ##//base_typename//##.


Revision [17656]

Edited on 2015-05-27 11:09:24 by FxMwikki [Added some complements when using Union]
Additions:
In ##//typename//## (the derived user-defined type), the fields can share the same memory space than the ##//base_typename//## only if ##//typename//## is a ##[[KeyPgUnion Union]]##. Here it does not matter whether ##//base_typename//## is a ##[[KeyPgUnion Union]]## or not.
If only ##//base_typename//## is a ##[[KeyPgUnion Union]]##, then it will not be affected by fields from ##//typename//## (the derived user-defined type).


Revision [17248]

Edited on 2014-09-07 04:35:58 by FxMwikki [wording - avoided inappropriate casting in the second example (casting only following the Is operato]
Additions:
##**Extends**## declares ##//typename//## to be derived from ##//base_typename//##. The derived user-defined type, ##//typename//##, inherits fields and methods of the ##//base_typename//## base type. ##//typename//## objects may be used in place of ##//base_typename//## objects. Fields and methods inherited from ##//base_typename//## will be implicitly accessible like regular members of ##//typename//##.
However, a regular member will shadow an inherited member if they have the same identifier. The ##[[KeyPgBase Base (member access)]]## keyword can be used to explicitly access members of the base type shadowed by local members.
Print " " & p->name, " " & p->ObjectRealType, " ";
Deletions:
##**Extends**## declares ##//typename//## to be derived from ##//base_typename//##. The derived user-defined type, ##//typename//##, inherits fields and methods of the ##//base_typename//## base type. ##//typename//## objects may be used in place of ##//base_typename//## objects. Fields and methods inherited from ##//base_typename//## will be implicitly accessible like regular members of ##//typename//##. However, a regular member will shadow an inherited member if they have the same identifier. The ##[[KeyPgBase Base (member access)]]## keyword can be used to explicitly access members of the base type.
Print " " & Cast(animal Ptr, p)->name, " " & p->ObjectRealType, " ";


Revision [16996]

Edited on 2014-01-17 03:12:51 by FxMwikki [The user defined type can also be an Union]
Additions:
[[KeyPgType Type]]|[[KeyPgUnion Union]] //typename// **Extends** //base_typename//
End [[KeyPgType Type]]|[[KeyPgUnion Union]]
- ##[[KeyPgUnion Union]]##
Deletions:
[[KeyPgType Type]] //typename// **Extends** //base_typename//
End [[KeyPgType Type]]


Revision [16932]

Edited on 2013-08-31 19:10:27 by CountingPine [It's good to find and update these stale references to v0.25.]
Additions:
**Warning:** Before fbc version 0.24, these five keywords dedicated to inheritance ##**Extends**##, ##[[KeyPgBase Base (member access)]]##, ##[[KeyPgBaseInit Base (initializer)]]##, ##[[KeyPgObject Object]]## and ##[[KeyPgOpIs Operator Is]]## were not supported. Three new keywords ##[[KeyPgVirtual Virtual]]##, ##[[KeyPgAbstract Abstract]]##, and ##[[KeyPgOverride Override]]## come with fbc version 0.90.
Deletions:
**Warning:** Before fbc version 0.24, these five keywords dedicated to inheritance ##**Extends**##, ##[[KeyPgBase Base (member access)]]##, ##[[KeyPgBaseInit Base (initializer)]]##, ##[[KeyPgObject Object]]## and ##[[KeyPgOpIs Operator Is]]## are not supported. Three new keywords ##[[KeyPgVirtual Virtual]]##, ##[[KeyPgAbstract Abstract]]##, and ##[[KeyPgOverride Override]]## come with fbc version 0.25 (version in preview for the version 0.90).


Revision [16930]

Edited on 2013-08-31 14:46:37 by FxMwikki [the fbc version 0.25 is in preview for the version 0.90]
Additions:
**Warning:** Before fbc version 0.24, these five keywords dedicated to inheritance ##**Extends**##, ##[[KeyPgBase Base (member access)]]##, ##[[KeyPgBaseInit Base (initializer)]]##, ##[[KeyPgObject Object]]## and ##[[KeyPgOpIs Operator Is]]## are not supported. Three new keywords ##[[KeyPgVirtual Virtual]]##, ##[[KeyPgAbstract Abstract]]##, and ##[[KeyPgOverride Override]]## come with fbc version 0.25 (version in preview for the version 0.90).
Deletions:
**Warning:** Before fbc version 0.24, these five keywords dedicated to inheritance ##**Extends**##, ##[[KeyPgBase Base (member access)]]##, ##[[KeyPgBaseInit Base (initializer)]]##, ##[[KeyPgObject Object]]## and ##[[KeyPgOpIs Operator Is]]## are not supported. Three new keywords ##[[KeyPgVirtual Virtual]]##, ##[[KeyPgAbstract Abstract]]##, and ##[[KeyPgOverride Override]]## come with fbc version 0.25.


Revision [16651]

Edited on 2013-03-18 23:20:53 by CountingPine [I don't think we use Sleep at the end of official examples unless necessary.]
Deletions:
Sleep


Revision [16650]

Edited on 2013-03-16 18:30:58 by FxMwikki [Added: Example using all eight keywords of inheritance]
Additions:
{{fbdoc item="filename" value="examples/manual/udt/extends1.bas"}}%%(freebasic)
{{fbdoc item="filename" value="examples/manual/udt/extends2.bas"}}%%(freebasic)
' Example using all eight keywords of inheritance:
' 'Extends', 'Base.', 'Base()', 'Object', 'Is' operator, 'Virtual', 'Abstract', 'Override'
Type root Extends Object ' 'Extends' to activate RTTI by inheritance of predefined Object type
Declare Function ObjectHierarchy () As String
Declare Abstract Function ObjectRealType () As String ' 'Abstract' declares function without local body
' which must be overriden
Declare Virtual Destructor () ' 'Virtual' declares destructor with body ('Abstract' forbidden)
Protected:
Declare Constructor () ' to avoid user construction from root
Declare Constructor (Byref rhs As root) '' to avoid user copy-construction from root
End Type ' derived type may be member data empty
Constructor root ()
Function root.ObjectHierarchy () As String
Return "Object(forRTTI) <- root"
End Function
Virtual Destructor root ()
Print "root destructor"
End Destructor
Type animal Extends root ' 'Extends' to inherit of root
Declare Constructor (Byref _name As String = "")
Declare Function ObjectHierarchy () As String
Declare Virtual Function ObjectRealType () As String Override ' 'Virtual' declares function with local
' body which can be overriden
' 'Override' to check if the function is
' well an override
Dim name As String
Declare virtual Destructor () Override ' 'Virtual' declares destructor with local body
' 'Override' to check if the destructor is well an override
Constructor animal (Byref _name As String = "")
This.name = _name
Function animal.ObjectHierarchy () As String
Return Base.ObjectHierarchy & " <- animal" ' 'Base.' allows to access to parent member function
End Function
Virtual Function animal.ObjectRealType () As String
Return "animal"
End Function
Virtual Destructor animal ()
Print " animal destructor: " & This.name
End Destructor
Type dog Extends animal ' 'Extends' to inherit of animal
Declare Constructor (Byref _name As String = "")
Declare Function ObjectHierarchy () As String
Declare Function ObjectRealType () As String Override ' 'Override' to check if the function is well an
' override
Declare Destructor () Override ' 'Override' to check if the destructor is well an override
End Type ' derived type may be member data empty
Constructor dog (Byref _name As String = "")
Base(_name) ' 'Base()' allows to call parent constructor
Function dog.ObjectHierarchy () As String
Return Base.ObjectHierarchy & " <- dog" ' 'Base.' allows to access to parent member function
End Function
Function dog.ObjectRealType () As String
Return "dog"
End Function
Destructor dog ()
Print " dog destructor: " & This.name
End Destructor
Type cat Extends animal ' 'Extends' to inherit of animal
Declare Constructor (Byref _name As String = "")
Declare Function ObjectHierarchy () As String
Declare Function ObjectRealType () As String Override ' 'Override' to check if the function is well an
' override
Declare Destructor () Override ' 'Override' to check if the destructor is well an override
End Type ' derived type may be member data empty
Constructor cat (Byref _name As String = "")
Base(_name) ' 'Base()' allows to call parent constructor
Function cat.ObjectHierarchy () As String
Return Base.ObjectHierarchy & " <- cat" ' 'Base.' allows to access to parent member function
End Function
Function cat.ObjectRealType () As String
Return "cat"
End Function
Destructor cat ()
Print " cat destructor: " & This.name
End Destructor
Sub PrintInfo (Byval p As root Ptr) ' must be put after definition of animal type, dog type and cat type
Print " " & Cast(animal Ptr, p)->name, " " & p->ObjectRealType, " ";
If *p Is dog Then ' 'Is' allows to check compatibility with type symbol
Print Cast(dog Ptr, p)->ObjectHierarchy
Elseif *p Is cat Then ' 'Is' allows to check compatibility with type symbol
Print Cast(cat Ptr, p)->ObjectHierarchy
Elseif *p Is animal Then ' 'Is' allows to check compatibility with type symbol
Print Cast(animal Ptr, p)->ObjectHierarchy
End If
Print "Name:", "Object (real): Hierarchy:"
Dim a As root Ptr = New animal("Mouse")
PrintInfo(a)
Dim d As root Ptr = New dog("Buddy")
PrintInfo(d)
Dim c As root Ptr = New cat("Tiger")
Printinfo(c)
Delete a
Delete d
Delete c
Sleep
Deletions:
{{fbdoc item="filename" value="examples/manual/udt/extends.bas"}}%%(freebasic)


Revision [16513]

Edited on 2012-12-26 13:15:28 by FxMwikki [Rename 'overriding' when misleading by using 'shadowing']
Additions:
##**Extends**## declares ##//typename//## to be derived from ##//base_typename//##. The derived user-defined type, ##//typename//##, inherits fields and methods of the ##//base_typename//## base type. ##//typename//## objects may be used in place of ##//base_typename//## objects. Fields and methods inherited from ##//base_typename//## will be implicitly accessible like regular members of ##//typename//##. However, a regular member will shadow an inherited member if they have the same identifier. The ##[[KeyPgBase Base (member access)]]## keyword can be used to explicitly access members of the base type.
Deletions:
##**Extends**## declares ##//typename//## to be derived from ##//base_typename//##. The derived user-defined type, ##//typename//##, inherits fields and methods of the ##//base_typename//## base type. ##//typename//## objects may be used in place of ##//base_typename//## objects. Fields and methods inherited from ##//base_typename//## will be implicitly accessible like regular members of ##//typename//##. However, regular members will override inherited members if they have the same identifier. The ##[[KeyPgBase Base (member access)]]## keyword can be used to explicitly access members of the base type.


Revision [16512]

Edited on 2012-12-26 12:50:05 by FxMwikki [Added reference to OVERRIDE]
Additions:
Extending the built-in ##[[KeyPgObject Object]]## type allows a user-defined type to be used with ##[[KeyPgOpIs Operator Is]]## to perform run-time type checks, to support ##[[KeyPgVirtual Virtual]]## and ##[[KeyPgAbstract Abstract]]## methods, and to use the ##[[KeyPgOverride Override]]## method attribute.
**Warning:** Before fbc version 0.24, these five keywords dedicated to inheritance ##**Extends**##, ##[[KeyPgBase Base (member access)]]##, ##[[KeyPgBaseInit Base (initializer)]]##, ##[[KeyPgObject Object]]## and ##[[KeyPgOpIs Operator Is]]## are not supported. Three new keywords ##[[KeyPgVirtual Virtual]]##, ##[[KeyPgAbstract Abstract]]##, and ##[[KeyPgOverride Override]]## come with fbc version 0.25.
- ##[[KeyPgOverride Override]]##
Deletions:
Extending the built-in ##[[KeyPgObject Object]]## type allows a user-defined type to be used with ##[[KeyPgOpIs Operator Is]]## to perform run-time type checks, and to support ##[[KeyPgVirtual Virtual]]## and ##[[KeyPgAbstract Abstract]]## methods.
**Warning:** Before fbc version 0.24, these five keywords dedicated to inheritance ##**Extends**##, ##[[KeyPgBase Base (member access)]]##, ##[[KeyPgBaseInit Base (initializer)]]##, ##[[KeyPgObject Object]]## and ##[[KeyPgOpIs Operator Is]]## are not supported. Two new keywords ##[[KeyPgVirtual Virtual]]## and ##[[KeyPgAbstract Abstract]]## come with fbc version 0.25.


Revision [16466]

Edited on 2012-11-24 04:30:57 by FxMwikki [Added in Warning: Two new keywords Virtual and Abstract come with fbc version 0.25]
Additions:
**Warning:** Before fbc version 0.24, these five keywords dedicated to inheritance ##**Extends**##, ##[[KeyPgBase Base (member access)]]##, ##[[KeyPgBaseInit Base (initializer)]]##, ##[[KeyPgObject Object]]## and ##[[KeyPgOpIs Operator Is]]## are not supported. Two new keywords ##[[KeyPgVirtual Virtual]]## and ##[[KeyPgAbstract Abstract]]## come with fbc version 0.25.
Deletions:
**Warning:** Before fbc version 0.24, these five keywords dedicated to inheritance ##**Extends**##, ##[[KeyPgBase Base (member access)]]##, ##[[KeyPgBaseInit Base (initializer)]]##, ##[[KeyPgObject Object]]## and ##[[KeyPgOpIs Operator Is]]## are not supported.


Revision [16456]

Edited on 2012-11-19 06:29:16 by FxMwikki [Wording: replace 'call' with 'support']
Additions:
Extending the built-in ##[[KeyPgObject Object]]## type allows a user-defined type to be used with ##[[KeyPgOpIs Operator Is]]## to perform run-time type checks, and to support ##[[KeyPgVirtual Virtual]]## and ##[[KeyPgAbstract Abstract]]## methods.
Deletions:
Extending the built-in ##[[KeyPgObject Object]]## type allows a user-defined type to be used with ##[[KeyPgOpIs Operator Is]]## to perform run-time type checks, and to call ##[[KeyPgVirtual Virtual]]## and ##[[KeyPgAbstract Abstract]]## methods.


Revision [16452]

Edited on 2012-11-17 08:45:55 by FxMwikki [Added some references and links to Virtual/Abstract methods]
Additions:
Extending the built-in ##[[KeyPgObject Object]]## type allows a user-defined type to be used with ##[[KeyPgOpIs Operator Is]]## to perform run-time type checks, and to call ##[[KeyPgVirtual Virtual]]## and ##[[KeyPgAbstract Abstract]]## methods.
**Note:** Derived UDT pointer can only be casted to "compatible" pointer types (up/down the inheritance hierarchy) or ##[[KeyPgAny Any]] [[KeyPgPtr Ptr]]##. Otherwise, cast to ##[[KeyPgAny Any]] [[KeyPgPtr Ptr]]## first.
- ##[[KeyPgVirtual Virtual]]##
- ##[[KeyPgAbstract Abstract]]##
Deletions:
Extending the built-in ##[[KeyPgObject Object]]## type allows a user-defined type to be used with ##[[KeyPgOpIs Operator Is]]## to perform run-time type checks.
**Remark:** Derived UDT pointer can only be casted to "compatible" pointer types (up/down the inheritance hierarchy) or ##[[KeyPgAny Any]] [[KeyPgPtr Ptr]]##. Otherwise, cast to ##[[KeyPgAny Any]] [[KeyPgPtr Ptr]]## first.


Revision [16271]

Edited on 2012-08-13 10:42:31 by CountingPine [Format 'Any Ptr' refs as code+wikilinks]
Additions:
**Remark:** Derived UDT pointer can only be casted to "compatible" pointer types (up/down the inheritance hierarchy) or ##[[KeyPgAny Any]] [[KeyPgPtr Ptr]]##. Otherwise, cast to ##[[KeyPgAny Any]] [[KeyPgPtr Ptr]]## first.
Deletions:
**Remark:** Derived UDT pointer can only be casted to "compatible" pointer types (up/down the inheritance hierarchy) or Any Ptr. Otherwise, cast to Any Ptr first.


Revision [16270]

Edited on 2012-08-13 10:24:18 by FxMwikki [Adding an example with "Extends" only among inheritance keywords]
Additions:
Print "Name: "; This.name; " Age:"; This.age
Type Teacher Extends SchoolMember 'Represents a teacher derived from SchoolMember'
Print "Salary:"; This.salary
Type Student Extends SchoolMember 'Represents a student derived from SchoolMember'
Print "Marks:"; This.marks
Deletions:
Print "Name: "; This.name; " Age: "; This.age
Type Teacher Extends SchoolMember 'Represents a teacher'
Print "Salary: "; This.salary
Type Student Extends SchoolMember 'Represents a student'
Print "Marks: "; This.marks


Revision [16269]

Edited on 2012-08-13 10:11:41 by FxMwikki [Adding an example with "Extends" only among inheritance keywords]
Additions:
t.Tell()
s.Tell()
Deletions:
t.Tell
s.Tell


Revision [16268]

Edited on 2012-08-13 06:10:43 by FxMwikki [Adding an example with "Extends" only among inheritance keywords]
Additions:
{{fbdoc item="filename" value="examples/manual/udt/extends.bas"}}%%(freebasic)
Type SchoolMember 'Represents any school member'
Declare Constructor ()
Declare Sub Init (Byref _name As String, Byval _age As Integer)
As String name
As Integer age
End Type
Constructor SchoolMember ()
Print "Initialized SchoolMember"
End Constructor
Sub SchoolMember.Init (Byref _name As String, Byval _age As Integer)
This.name = _name
This.age = _age
Print "Name: "; This.name; " Age: "; This.age
End Sub
Type Teacher Extends SchoolMember 'Represents a teacher'
Declare Constructor (Byref _name As String, Byval _age As Integer, Byval _salary As Integer)
As Integer salary
Declare Sub Tell ()
End Type
Constructor Teacher (Byref _name As String, Byval _age As Integer, Byval _salary As Integer)
Print "Initialized Teacher"
This.Init(_name, _age) 'implicit access to base member procedure'
This.salary = _salary
End Constructor
Sub Teacher.Tell ()
Print "Salary: "; This.salary
End Sub
Type Student Extends SchoolMember 'Represents a student'
Declare Constructor (Byref _name As String, Byval _age As Integer, Byval _marks As Integer)
As Integer marks
Declare Sub Tell ()
End Type
Constructor Student (Byref _name As String, Byval _age As Integer, Byval _marks As Integer)
Print "Initialized Student"
This.Init(_name, _age) 'implicit access to base member procedure'
This.marks = _marks
End Constructor
Sub Student.Tell ()
Print "Marks: "; This.marks
End Sub
Dim As Teacher t = Teacher("Mrs. Shrividya", 40, 30000)
t.Tell
Print
Dim As Student s = Student("Swaroop", 22, 75)
s.Tell
%%


Revision [16267]

Edited on 2012-08-12 13:08:13 by FxMwikki [Adding some links and description complement]
Additions:
##**Extends**## declares ##//typename//## to be derived from ##//base_typename//##. The derived user-defined type, ##//typename//##, inherits fields and methods of the ##//base_typename//## base type. ##//typename//## objects may be used in place of ##//base_typename//## objects. Fields and methods inherited from ##//base_typename//## will be implicitly accessible like regular members of ##//typename//##. However, regular members will override inherited members if they have the same identifier. The ##[[KeyPgBase Base (member access)]]## keyword can be used to explicitly access members of the base type.
The ##[[KeyPgBaseInit Base (initializer)]]## keyword can be used at the top of constructor of derived user-defined type. It allows to specify an initializer or constructor call for the base type.
Deletions:
##**Extends**## declares ##//typename//## to be derived from ##//base_typename//##. The derived user-defined type, ##//typename//##, inherits fields and methods of the ##//base_typename//## base type. ##//typename//## objects may be used in place of ##//base_typename//## objects. Fields and methods inherited from ##//base_typename//## will be implicitly accessible like regular members of ##//typename//##. However, regular members will override inherited members if they have the same identifier. The ##[[KeyPgBase Base]]## keyword can be used to explicitly access members of the base type.


Revision [16266]

Edited on 2012-08-12 11:32:44 by FxMwikki [Adding some links]
Additions:
**Warning:** Before fbc version 0.24, these five keywords dedicated to inheritance ##**Extends**##, ##[[KeyPgBase Base (member access)]]##, ##[[KeyPgBaseInit Base (initializer)]]##, ##[[KeyPgObject Object]]## and ##[[KeyPgOpIs Operator Is]]## are not supported.
- ##[[KeyPgBaseInit Base (initializer)]]##
- ##[[KeyPgBase Base (member access)]]##
- ##[[KeyPgObject Object]]##
Deletions:
**Warning:** Before fbc version 0.24, these four keywords dedicated to inheritance ##**Extends**##, ##[[KeyPgBase Base]]##, ##[[KeyPgObject Object]]## and ##[[KeyPgOpIs Operator Is]]## are not supported.
- ##[[KeyPgBase Base]]##


Revision [16230]

Edited on 2012-07-31 04:05:35 by FxMwikki [Remark: Derived UDT pointer can only be casted to "compatible" pointer types or Any Ptr]
Additions:
**Remark:** Derived UDT pointer can only be casted to "compatible" pointer types (up/down the inheritance hierarchy) or Any Ptr. Otherwise, cast to Any Ptr first.


Revision [16222]

Edited on 2012-07-19 06:03:53 by FxMwikki [Before fbc 0.24, compiler does not support inheritance]
Additions:
**Warning:** Before fbc version 0.24, these four keywords dedicated to inheritance ##**Extends**##, ##[[KeyPgBase Base]]##, ##[[KeyPgObject Object]]## and ##[[KeyPgOpIs Operator Is]]## are not supported.


Revision [15826]

Edited on 2012-01-24 15:37:57 by CountingPine [Formatting]
Additions:
##**Extends**## declares ##//typename//## to be derived from ##//base_typename//##. The derived user-defined type, ##//typename//##, inherits fields and methods of the ##//base_typename//## base type. ##//typename//## objects may be used in place of ##//base_typename//## objects. Fields and methods inherited from ##//base_typename//## will be implicitly accessible like regular members of ##//typename//##. However, regular members will override inherited members if they have the same identifier. The ##[[KeyPgBase Base]]## keyword can be used to explicitly access members of the base type.
Deletions:
**Extends** declares //typename// to be derived from //base_typename//. The derived user-defined type, //typename//, inherits fields and methods of the //base_typename// base type. //typename// objects may be used in place of //base_typename// objects. Fields and methods inherited from //base_typename// will be implicitly accessible like regular members of //typename//. However, regular members will override inherited members if they have the same identifier. The ##[[KeyPgBase Base]]## keyword can be used to explicitly access members of the base type.


Revision [15814]

Edited on 2012-01-24 09:07:05 by DkLwikki [Add EXTENDS description]
Additions:
- ##[[KeyPgOpIs Operator Is]]##
Deletions:
- ##[[KeyPgOpIs Is]]##


Revision [15813]

Edited on 2012-01-24 09:06:24 by DkLwikki [Add EXTENDS description]
Additions:
**Extends** declares //typename// to be derived from //base_typename//. The derived user-defined type, //typename//, inherits fields and methods of the //base_typename// base type. //typename// objects may be used in place of //base_typename// objects. Fields and methods inherited from //base_typename// will be implicitly accessible like regular members of //typename//. However, regular members will override inherited members if they have the same identifier. The ##[[KeyPgBase Base]]## keyword can be used to explicitly access members of the base type.
Deletions:
**Extends** declares //typename// to be derived from //base_typename//. The derived user-defined type, //typename//, inherits members and methods of the //base_typename// base type. //typename// objects may be used in place of //base_typename// objects. Fields and methods inherited from //base_typename// will be implicitly accessible like regular fields and methods of //typename//. However, regular members will override inherited members if they have the same identifier. The ##[[KeyPgBase Base]]## keyword can be used to explicitly access members of the base type.


Revision [15812]

Edited on 2012-01-24 09:05:49 by DkLwikki [Add EXTENDS description]
Additions:
[[KeyPgType Type]] //typename// **Extends** //base_typename//
...
End [[KeyPgType Type]]
**Extends** declares //typename// to be derived from //base_typename//. The derived user-defined type, //typename//, inherits members and methods of the //base_typename// base type. //typename// objects may be used in place of //base_typename// objects. Fields and methods inherited from //base_typename// will be implicitly accessible like regular fields and methods of //typename//. However, regular members will override inherited members if they have the same identifier. The ##[[KeyPgBase Base]]## keyword can be used to explicitly access members of the base type.

User-defined types that extend another type will include the base type structure at their beginning, and their size as reported by ##[[KeyPgSizeOf sizeof()]]## is the sum of their base type's size plus the size needed for any regular members. Since the inherited members make sure that the structure is not empty, a derived type is not required to have regular members of its own.

Extending the built-in ##[[KeyPgObject Object]]## type allows a user-defined type to be used with ##[[KeyPgOpIs Operator Is]]## to perform run-time type checks.
- Not available in the //[[CompilerOptlang -lang qb]]// dialect unless referenced with the alias ##**""__Extends""**##.
- New to ""FreeBASIC""
- ##[[KeyPgOpIs Is]]##
Deletions:
[[KeyPgType Type]] //typename// **Extends** //base_typename//
...
End [[KeyPgType Type]]
{{fbdoc item="param"}}
- ##[[KeyPgOpIs Operator Is]]##


Revision [15810]

Edited on 2012-01-24 03:22:02 by FxMwikki [Is -> Operator Is (in links list)]
Deletions:


Revision [15808]

Edited on 2012-01-24 02:23:14 by FxMwikki [Is -> Operator Is (in links link)]
Additions:
- ##[[KeyPgOpIs Operator Is]]##
Deletions:
- ##[[KeyPgIs Is]]##


Revision [15644]

Edited on 2012-01-13 11:27:45 by CountingPine [New Extends keyword page (stub)]
Additions:
{{fbdoc item="param"}}


Revision [15643]

The oldest known version of this page was created on 2012-01-13 11:26:24 by CountingPine [New Extends keyword page (stub)]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode