D
danbraund
Hi everyone, I'm a long time C coder, who is coding his final year
project in C++ to run under the MIT click routing system. Being fairly
new to the OO side of the language, my problem is this:
In C++, how can I define a global array whose size is determined by
parameters passed to a class?
The array is of static size once defined, but the parameters of course
arent read until the config function is called at class startup. is
there a way of prototyping the array with mynewarray[](int blah)[](int
bleh) or something similar, assuming blah and bleh are the int values
read from the parameters list in the config function? Both are defined
in the header, along with the struct type for the array I wish to
create. I did try just defining it then and there in the header, but
got an error like this:
myheader.hh:34: error: invalid use of non-static data member
'My_Element::bleh'
myheader.hh:56: error: from this location
myheader.hh:56: error: array bound is not an integer constant
myheader.hh:33: error: invalid use of non-static data member
'My_Element::blah'
myheader.hh:56: error: from this location
myheader.hh:56: error: array bound is not an integer constant
Like I say, Im pretty new to C++, and there must be a way of just
prototyping the variables or something, then initialising the array
properly once the parameters have been passed.
I did try struct mytype mynewarray[][]; in the header, and mytype
mynewarray[blah][bleh] in the init function, but it didnt like that
either.
Thanks in advance for any insight, this is driving me mad.
Daniel
project in C++ to run under the MIT click routing system. Being fairly
new to the OO side of the language, my problem is this:
In C++, how can I define a global array whose size is determined by
parameters passed to a class?
The array is of static size once defined, but the parameters of course
arent read until the config function is called at class startup. is
there a way of prototyping the array with mynewarray[](int blah)[](int
bleh) or something similar, assuming blah and bleh are the int values
read from the parameters list in the config function? Both are defined
in the header, along with the struct type for the array I wish to
create. I did try just defining it then and there in the header, but
got an error like this:
myheader.hh:34: error: invalid use of non-static data member
'My_Element::bleh'
myheader.hh:56: error: from this location
myheader.hh:56: error: array bound is not an integer constant
myheader.hh:33: error: invalid use of non-static data member
'My_Element::blah'
myheader.hh:56: error: from this location
myheader.hh:56: error: array bound is not an integer constant
Like I say, Im pretty new to C++, and there must be a way of just
prototyping the variables or something, then initialising the array
properly once the parameters have been passed.
I did try struct mytype mynewarray[][]; in the header, and mytype
mynewarray[blah][bleh] in the init function, but it didnt like that
either.
Thanks in advance for any insight, this is driving me mad.
Daniel