- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I'm trying to create an array of pointers. Well, the objective is an array of objects, which can contain any object that extends a certain base class.
I have a base class "object", and a derived class "sphere" ("TYPE, extends(object) :: sphere"). Here's an example of what I'm trying to do:class(object), pointer :: objects(:)
type(sphere), target :: s1
ALLOCATE(objects(0:numObjects-1), mold=s1)
objects(0) => s1
The last line gives error #8524 "The syntax of this data pointer assignment is incorrect: either 'bound spec' or 'bound remapping' is expected in this context. [0]"
However, the following works fine (but I need an array):class(object), pointer :: obj
type(sphere), target :: s1
obj => s1
One thing that sort of works is "objects(0:0) => s1", but that seems to resize the array to 0:0.
What am I doing wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[fortran]type container class(object), pointer :: obj end type container type(container), allocatable, dimension(:) :: objects allocate (objects(0:num_objects)) objects(0)%obj => s1[/fortran]
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[fortran]type container class(object), pointer :: obj end type container type(container), allocatable, dimension(:) :: objects allocate (objects(0:num_objects)) objects(0)%obj => s1[/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can cleanup the messiness by using an FPP macro.
However, the VS Debugger will not expand the macro (a feature I would like to see added), thus debugging is a bit complicated as you have to manually expand the macro in your watch expressions.
I use this technique a lot since it makes reading the code much clearer.
You can use an inlined function in Fortran on the RHS of =but unfortunately you cannot use it on the LHS of =. You can use an FPPmacro on either side.
Jim Dempsey

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page