Hi,

The subject is quite a mouthful, so here is the gist of what I'm trying
to do:

class MyClass {
public:
  MyClass(float *arr1D, const int width, const int comps)
    : _arr3D((float (*)[width][comps])arr1D) {}
protected:
  const float (*const _arr3D)[???][???];
};

The idea is to pass in a flattened pointer, pointing to a dynamically
allocated piece of memory, and convert it back to a multidimensionally
indexable array.

Herein lies the dilemma. In order to declare the pointer I need to
supply bounds information. However, in a dynamically allocated situation
this information can only come from outside the class. I can't see any
way to embed this constant pointer inside the class - however, it's
quite easy to assign it later in a non-const declaration.

Is this even possible in the language? The logical syntax would appear
to be:

protected:
  const float (*const _arr3D)[][];

And to delay stride binding until the constructor is analysed. Intel
C/C++ goes some way towards this (GCC 4.1 fails on this statement
instantly) by allowing this program to compile. However, an error is
still flagged if any attempts to access the array are made.

-- 
Jay L. T. Cornwall
http://www.jcornwall.me.uk/

Reply via email to