Note that there are some explanatory texts on larger screens.

plurals
  1. POOverloaded functions returning pointers to a base type alongside an abstract interface in fortran 2003?
    primarykey
    data
    text
    <p>I'm writing a linked list structure in Fortran2003. The nodes in this linked list come in two varieties that alternate. The list represents a topological ring of edges, each edge is bounded by two vertices, and each vertex connects to two edges. These structures are declared as an abstract NODE_T type, and implemented by two subclasses, VN_T and EN_T. A VN_T points to two EN_Ts, and vice versa. Since the list alternates between types, the pointers are stored in the subclasses. My problem is with adding type bound functions (methods?) to VN_T and EN_T that are called NEXT() and PREV(), and that do the right thing via polymorphism. VN_T%NEXT() should skip on <em>two</em> steps, and get the next VN_T (that is separated from the starting one by an EN_T).</p> <p>My type/class definitions are as follows:</p> <pre><code>TYPE, ABSTRACT :: NODE_T INTEGER :: IENT INTEGER :: ISIDE INTEGER :: ISUBTYPE INTEGER :: IPAD CONTAINS PROCEDURE(NEXTA), DEFERRED :: NEXT PROCEDURE(PREVA), DEFERRED :: PREV END TYPE NODE_T ABSTRACT INTERFACE FUNCTION NEXTA(PENT) IMPORT NODE_T CLASS(NODE_T), POINTER :: NEXTA CLASS(NODE_T) :: PENT END FUNCTION FUNCTION PREVA(PENT) IMPORT NODE_T CLASS(NODE_T), POINTER :: PREVA CLASS(NODE_T) :: PENT END FUNCTION END INTERFACE TYPE, EXTENDS(NODE_T) :: VN_T DOUBLE PRECISION DT CLASS(EN_T), POINTER :: N CLASS(EN_T), POINTER :: P CONTAINS PROCEDURE :: NEXT =&gt; NEXTV PROCEDURE :: PREV =&gt; PREVV END TYPE TYPE, EXTENDS(NODE_T) :: EN_T CLASS(VN_T), POINTER :: N CLASS(VN_T), POINTER :: P CONTAINS PROCEDURE :: NEXT =&gt; NEXTE PROCEDURE :: PREV =&gt; PREVE END TYPE </code></pre> <p>The implementations of the next/prev routines are all much the same, the four combinations of next/prev and EN/VN:</p> <pre><code>FUNCTION NEXTE(PENT) CLASS(NODE_T), POINTER :: NEXTE CLASS(EN_T) PENT NEXTE =&gt; PENT%N%N END FUNCTION </code></pre> <p>When I call these functions:</p> <pre><code>CLASS(NODE_T), POINTER :: NODE1, NODE2 NODE2 =&gt; NODE1%NEXT() </code></pre> <p>Then my compiler (Intel FORTRAN XE Composer 2011, i.e. v12.0) complains with the message</p> <pre><code>error #8314: If the rightmost part-name is of abstract type, data-ref shall be polymorphic [NEXT] NODE2 =&gt; NODE1%NEXT() ---------------------------^ </code></pre> <p>Which based on this <a href="http://software.intel.com/en-us/articles/abstract-type-usage-with-intelr-fortran-compiler/" rel="nofollow">this documentation</a> seems to indicate that it is trying to call the procdure NEXT on the <em>base</em> class rather than selecting one of the subclass implementations (which it should be able to do based on the concrete type of NODE1 which is on the right hand side, right?).</p> <p>I'm new at the OOP features of F2003, so I made a mockup of this pattern in JAVA which I got working to my satisfaction. Can anyone shed light on whether this is either a) a difference in the OOP behaviour of F2003, 2) a compiler bug or 3) just me being braindead...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload