samedi 18 septembre 2021

C++: class const static member definition need not be defined outside of the class

Straight to it as below.

class Play {
public:
const static int b=20; --> line 1
}

int main() {
cout << Play::b;
}

Output:
20

The above looks like a definition. is it? Seems to contradict the below from lots of C++ articles.

The declaration of a static data member in the member list of a class is not a definition. You must define the static member outside of the class declaration, in namespace scope

Aucun commentaire:

Enregistrer un commentaire