Should we define a static const
member outside of the class definition even if it is initialised inside the class?
#include<iostream>
using namespace std;
class abc
{
static const int period=5;
int arr[period];
public:
void display()
{
cout<<period<<endl;
}
};
const int abc::period;
int main()
{
abc a;
a.display();
return 0;
}
After commenting // const int abc::period;
, both versions of the code run fine on gcc 4.3.4. So I want to ask why do both versions work and which one is standard compliant?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…