Sounds like an ideal Iliffe vector application.
Let us know how it goes.
Sounds like an ideal Iliffe vector application.
Let us know how it goes.
that is what my question is about, let me rephrase it::
I want to create a class which creates an array[a,b] of arbitrary sizes by the constructor.
I now found a way to create a 1-dim array by assert, but I always fail by trying to create a 2-dim array.
exit status 1
array size in operator new must be constant
Which would be the correct way to do that?
#include <cassert>
class tMenu {
protected:
char * list;
char MENULEN, CAPTLEN;
public:
tMenu (char menulen, char captlen) // constructor
{
assert(menulen > 0);
assert(captlen > 0);
list = new char[menulen]; // works fine!
// list = new char[menulen][captlen]; // alternat. >> error!
MENULEN = menulen;
CAPTLEN = captlen;
}
~tMenu() // destructor
{
// Dynamically delete the array we allocated earlier
delete[] list ;
}
};
I now found a way to create a 1-dim array by assert,
assert is normally used to halt things when anomalous situations are encountered, to aid debugging.
Nothing at all to do with memory allocation
edit:
I think I found it out:
MENULEN = menulen;
CAPTLEN = captlen;
list = new char*[MENULEN];
for(int i = 0; i < MENULEN; i++)
{
list[i] = new char[CAPTLEN];
}
}