Hello forum, I was trying to write a quick and dirty ring buffer and have run into the following problem, I 'm not too sure what happens when I try to declare an array as a member of a class but initialise it in a constructor, e.g.
class myRingBuffer {
public:int daBuffer[];
myRingBuffer(int size) {
daBuffer;
}
};void setup() {
myRingBuffer mrb = myRingBuffer(10);
mrb.daBuffer[9] = 3;
Serial.begin(9600);
Serial.println(mrb.daBuffer[9]);
}void loop() {
}[/quote]
So, the above compiles, uploads and prints 3 on the serial monitor. But is it doing what I assume it is doing, that is creating a 10 integer long array when the constructor gets called? Or does the single line in the constructor simply call an address "size" integers down from the start of the array and discard the result? What I 'm driving at is, when I read/write to the array after I instantiate "mrb" am I using a legal address or am I groping at random somewhere in memory?
One final worry, when trying to encapsulate stuff to keep things tidy, is there any worthwhile performance difference if using typedef and data structures instead of C++ classes?