Why do I need a static here?

Why can I write this:

class VoiceManager
{
public:
    static const int mMaxNumOfVoices = 16;
    Voice mVoices[mMaxNumOfVoices];

private:
};

but I can not use this:

class VoiceManager
{
public:
    const int mMaxNumOfVoices = 16;
    Voice mVoices[mMaxNumOfVoices];

private:
};

It says: "the reference to the non-static element must be relative to a specific object"

But in both cases there mMaxNumOfVoicesis constand will be init before mVoicesinit (the compiler will execute the declaration order, no?).

But this is required static. Why?

+4
source share
2 answers

. , . , - static .

+16

const , , , . , , .

a static const , . , , . . , ( ), ​​ .

+1

Source: https://habr.com/ru/post/1668386/


All Articles