Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I make an array of cascadefilter?

I am making 1/3 octave band filters. I'd like to make 27 parallel Cascade filters for continuous signal filtering.

That is, I want to declare and use the following filters:
CNiIIRCascadeFilter filter0(CNiMath::LowPass,3);
CNiIIRCascadeFilter filter1(CNiMath::LowPass,3);
CNiIIRCascadeFilter filter2(CNiMath::LowPass,3);
......
CNiIIRCascadeFilter filter26(CNiMath::LowPass,3);

Is there any method to declare those filter using class array?
I tried,
CNiIIRCascadeFilter myFilter[27];
and
CNiIIRCascadeFilter pmyFilter;
pmyFilter = new CNiIIRCascadeFilter[27];

However, they return errors during compiling.

Thanks.
0 Kudos
Message 1 of 2
(2,969 Views)
The C2248 error that you're seeing from the Visual C++ compiler is because CNiIIRCascadeFilter's default constructor is private, hence it cannot be called when the array is allocated. Here is one way that you can work around this:

int i = 0;
const int count = 27;
CNiIIRCascadeFilter** filters = new CNiIIRCascadeFilter*[count];

for (i = 0; i < count; ++i)
filters[i] = new CNiIIRCascadeFilter(CNiMath::LowPass, 3);

// Use the array ...

for (i = 0; i < count; ++i)
delete filters[i];

delete filters;

There are other ways you could implement this to be more defensive and to ensure that delete is called. For example, you could use an STL vector of smart pointers such as boost.org's shared_ptr.

- Elton
0 Kudos
Message 2 of 2
(2,969 Views)