This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Constructors for dynamically allocated CLASS data


> On 7/15/2013 1:29 AM, Tobias Burnus wrote:

> John McFarland wrote:

> Quick question about constructors in Fortran 2003/08. Say I have an abstract base class such as Shape, with > child classes such as Circle, Square, etc. In C++, you can dynamically allocate these data using something  > like:
> Shape *s;
> s = new Circle(3);  // Construct a circle with radius=3

> Well, in principle you could do likewise in Fortran 2008:

> class(shape), allocatable :: s
> s = circle(3)

In case it's of interest, my workaround for doing this in Fortran 2003 is 

allocate(s,source=circle(3))

It like slightly clunky syntax but on slightly so.  

Damian

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]