new operator is giving me trouble

I wrote some C++ code that facilitates the use of moving average filters and can be used with Arduino to de-noise input signals. The code can be found here.

A new instance of MovingAverage is created as follows:

MovingAverage* movingAverage = new MovingAverage(5);

New data is added like this:

double measurement = analogRead(myPin)*scalingFactor;
movingAverage->add(measurement);

and the current average value is retrieved as follows:

movingAverage->getCurrentAverage();

The problem I'm facing is that the operator new fails. On the Arduino IDE, I tried the following code:

#include <new.h>
#include <MovingAverage.h>

MovingAverage * ma = new MovingAverage(10);

void setup() {
}

void loop() { 
}

which throws the following error:

MovingAverage/MovingAverage.cpp.o: In function `MovingAverage::MovingAverage(unsigned short)':
.../Electronix/arduino-1.0.2/libraries/MovingAverage/MovingAverage.cpp:19: undefined reference to `operator new[](unsigned int)'

I suspected that this is because of the attempt to dynamically allocate memory in MovingAverage.cpp. I then tried the following:

double * vector = new double[10];

and I got exactly the same error message. This means that new[] cannot be used in Arduino. Is there some way to work this around?

What version of the IDE are you using. Not all versions support new. What is in the new.h file you are including. The versions of the IDE that support new do not use an include file specifically to do so.

PaulS:
What version of the IDE are you using. Not all versions support new. What is in the new.h file you are including. The versions of the IDE that support new do not use an include file specifically to do so.

I'm using the Arduino IDE ver1.0.2 (2012.11.05) and my board is the Aduino Uno rev3. This new.h is a file I found in <arduino_base>/hardware/arduino/cores/arduino - it offers an implementation for new, but not for new[]. I think it is included by default in all projects anyway.

Add these lines to your project (eg. the main sketch):

void * operator new[] (size_t size) { return malloc(size); }
void operator delete[] (void * ptr) { free (ptr); }