Hi all,
I have a base type from which say 2 extended types are derived.
The reason behind is that base type provides type components and some
(mostly access) procedures, extended types differ only in the procedures (methods?) that are applicable to each extended type. Internal
components are the same.
All types are declared in their own module.
Only the extended types should appear in user code.
The point is, I need default initialization different in each extended
type (very short example follows - in any previous code I wrote I didn't
use extended types this way)
module base_mod
type base_t
real :: a(3)
..
module d1_t
use base_mod
type, extends(base_t) :: d1_t
base_t = [0., 0., 0.]
..
module d2_t
use base_mod
type, extends(base_t) :: d2_t
base_t = [1., 1., 1.]
or something else ?
Thanks in advance
Gigi
Hi all,
I have a base type from which say 2 extended types are derived.
The reason behind is that base type provides type components and some
(mostly access) procedures, extended types differ only in the procedures (methods?) that are applicable to each extended type. Internal
components are the same.
All types are declared in their own module.
Only the extended types should appear in user code.
The point is, I need default initialization different in each extended
type (very short example follows - in any previous code I wrote I didn't
use extended types this way)
module base_mod
type base_t
real :: a(3)
..
module d1_t
use base_mod
type, extends(base_t) :: d1_t
base_t = [0., 0., 0.]
..
module d2_t
use base_mod
type, extends(base_t) :: d2_t
base_t = [1., 1., 1.]
or something else ?
Thanks in advance
Gigi
GianLuigi Piacentini schrieb am Donnerstag, 11. November 2021 um 11:29:18 UTC+1:
I have a base type from which say 2 extended types are derived.
The point is, I need default initialization different in each extended
type (very short example follows - in any previous code I wrote I didn't use extended types this way)
It is not possible to specify default initialization of the base type's component in an extension.
However, if only the extended type is visible in user code, why not use two differently initialized base types,
with the same name for the type component?
It is not possible to specify default initialization of the base type's component in an extension.
However, if only the extended type is visible in user code, why not use two differently initialized base types,
with the same name for the type component?
I think you can do it in Java.Yes, but I have also base type procedures (say get, set, print and some
That is, I don't think the restriction is basic to OOP.
If only the extended types are used, it is usual to make the
base abstract.
But also, as noted, if the base is never used,That's a possibility, and is what I did in previous code on similar
put the variable declaration in each extended type.
I presume that there are other parts to the base, though it
should work either way.
On 11/11/21 20:17, gah4 wrote:
I think you can do it in Java.
That is, I don't think the restriction is basic to OOP.
If only the extended types are used, it is usual to make the
base abstract.
Yes, but I have also base type procedures (say get, set, print and some
other things) that are common to both extended types, and I would like
to leverage this commonalty.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 159 |
Nodes: | 16 (0 / 16) |
Uptime: | 98:56:18 |
Calls: | 3,209 |
Files: | 10,563 |
Messages: | 3,009,783 |