Blitz logo

Blitz Support :

From: John Bray (home_at_[hidden])
Date: 2005-02-15 05:38:20


As someone with a long background in Fortan 90 struggling to see how the
same features might be implemented, Blitz looks very useful, but I'm
confused how I could introduce Arrays into my own classes for dynamic
allocation.

In Fortran I'd have

MODULE fred
  REAL :: a1(2,4,5)
  REAL, POINTER :: a2(:,:,:)
CONTAINS
SUBROUTINE Allocate(x,y,z)
INTEGER,INTENT(IN) :: x,y,z
ALLOCATE (a2(x,y,z))
END SUBROUTINE Allocate
END MODULE fred

With Blitz in C++ I'd assume something like

#include <blitz/array.h>
using namespace blitz;

class Fred {
  Array<float,3> a1(2,4,5);
// Not sure how to define a2 here
public:
  void allocate(int x,int y, int z);
};

void Fred::allocate(int x, int y, int z) {
  Array<float,3> a2(x,y,z);
  return;
}

Now this is wrong because g++ objects to the definition of a1, and I
wanted a2 to be a class level variable, not local to allocate. The
dynamic array a2 is of course the more useful one to me.

I suspect this is due to my ignorance of C++, but none of the Blitz
examples try to do this kind of thing.

John