You cannot (generally) pass an arbitrary multidimensional array of functions to C or C ++, as in Java (I mention Java, because where your question history tells you that your experience lies).
There really is no way to support anything like array initializers for your class in the current standard, although there are some plans to change this in the next version, C ++ 0x.
If you want this to have the flexibility of, say, Java arrays (where clients can resize the specified array, you have several options. The first and best would be to use std::vector<> , which implements a dynamic array for you, but you can be limited to this built-in platform, you can also implement things yourself as a one-dimensional array and accept a block of dynamic memory.
class Foo { int *theArray_; unsigned int rows_; unsigned int cols_; public: Foo(int *theArray, int rows, int cols) : theArray_(theArray) , rows_(rows) , cols_(cols) { } void UseTheArray() {
Please note that in this case, the caller is responsible for transferring memory. Also consider using std::auto_ptr above instead of a raw pointer to find out who is responsible for destroying a block of memory when destroying an object.
Also note that you should not use the name _x - names beginning with an underscore contain a whole bunch of rules that you probably want to avoid thinking about.
EDIT: This is part of my original answer; it is not right:
<y> A multidimensional array in C ++ is just one block of memory. It is possible to accept a multidimensional array, similar to this only in one case - where you know in advance the exact dimensions of the array in the class. Then you can write something like:
class Foo { int coeff[3][6]; public: Foo(int _x[3][6]) : coeff(_x) {} };
Please note that the size of the array is fixed and cannot be changed by clients of your class. C>
Billy oneal
source share