Arrays in classes

Hi There,

I am looking for some help with arrays and classes. In my .h file I declare my array as so

private:
            
  int _pin;
  int _morseCode[3];

This should create an array with three int elements?

I have tried initializing this array in my constructor as follows:

_morseCode={1,2,3}

But this doesn't work, what am I doing wrong? Do I have to explicitly set each element?

All help is greatly appreciated.

If you have three values, shouldn't you have 4 places? have you tried int _morseCode[4] = {1,2,3}; ?

Joa

If you have three values, shouldn't you have 4 places

You only need extra elements in the case of strings, where you need an extra one for the terminating NULL.

I believe that an initializer like {1,2,3} only works when you declare the array. You can't use it as an assignment statement. You'll have to assign each element individually, like this:

_morseCode[0] = 1;
_morseCode[1] = 2;
_morseCode[2] = 3;

I have figured this out now, using the {1,2,3} when declaring the array works but it cannot be used as an assignment statement.

Thanks for all the help.