Initializing Static Member Arrays

1
2
3
4
5
6
class MyClass
{
    static int arr[5];
};

int MyClass::arr[5]={13,42,35,75,68};


I guess I can't remove the 5 from static int arr[5];, but Can I remove the 5 from the initialization line? If yes, will the length be determined by 5 or by the number of elements initialized?
This is OK:
1
2
3
4
5
6
class MyClass
{
    static int arr[];
};

int MyClass::arr[]={13,42,35,75,68};
Okay...this leaves just one question unanswered:

1
2
3
4
5
6
class MyCass
{
     static int arr[7];
};

int MyClass::arr[]={1,2,3,4,5};


Does this work (in which case arr's length is 7 and arr[5] and arr[6] are initialized to 0) or it produces an error (which means the compiler deduces from the initialization that arr's length is 5 but in the declaration it's arr[7] which causes a mismatch error) ?
The number of elements is as given in the class declaration (if no value is given then the number of elements are as given in the initialization list).
If the number of initialization values is less than the declaration, then the remaining ones are zero initialized.
Thanks for the answers! :)
Topic archived. No new replies allowed.