Instantiating an array of objects
-
Hi, I'm facing the following problem in trying to code a DSP application in C#. I need to create an array of objects of a class "cBiquad" using its default constructor. The number of cBiquad objects is "mnNumBiquads". How do I do this? I tried the following: int mnNumBiquads = (mnOrder + 1)/2; int[] Biquad = new int[mnNumBiquads]; for (int i = 0; i < mnNumBiquads; i++) { Biquad[i] = new cBiquad(); } However, this gives me the obvious error of not being able to implicitly convert cBiquad to int. Could somebody suggest what I could do?
-
Hi, I'm facing the following problem in trying to code a DSP application in C#. I need to create an array of objects of a class "cBiquad" using its default constructor. The number of cBiquad objects is "mnNumBiquads". How do I do this? I tried the following: int mnNumBiquads = (mnOrder + 1)/2; int[] Biquad = new int[mnNumBiquads]; for (int i = 0; i < mnNumBiquads; i++) { Biquad[i] = new cBiquad(); } However, this gives me the obvious error of not being able to implicitly convert cBiquad to int. Could somebody suggest what I could do?
crushinghellhammer wrote: Could somebody suggest what I could do?
int size = 10; cBiquad\[\] cba = new cBiquad\[size\]; for(int i = 0; i < size; i++) cba\[i\] = new cBiquad();
- Nick Parker
My Blog | My Articles -
crushinghellhammer wrote: Could somebody suggest what I could do?
int size = 10; cBiquad\[\] cba = new cBiquad\[size\]; for(int i = 0; i < size; i++) cba\[i\] = new cBiquad();
- Nick Parker
My Blog | My ArticlesThanks, Nick. I *just* figured out myself, as well. cBiquad[] arrBiquads = new cBiquad[mnNumBiquads]; for (int i = 0; i < mnNumBiquads; i++) { arrBiquads[i] = new cBiquad(); } Is there a more elegant way of doing this, as in instantiating the array in just one line, using the default cBiquad constructor. I mean: cBiquad[] arrBiquads = something...
-
Thanks, Nick. I *just* figured out myself, as well. cBiquad[] arrBiquads = new cBiquad[mnNumBiquads]; for (int i = 0; i < mnNumBiquads; i++) { arrBiquads[i] = new cBiquad(); } Is there a more elegant way of doing this, as in instantiating the array in just one line, using the default cBiquad constructor. I mean: cBiquad[] arrBiquads = something...
crushinghellhammer wrote: Is there a more elegant way of doing this Nope, that's about it. You could write a class factory of sorts that would take care of this for you, depending on what you are doing that may be overhead. - Nick Parker
My Blog | My Articles