#include<iostream>
using namespace std;
class A
{
private:
const int a=9;
public:
void display()
{
cout<<a;
}
};
int main()
{
A a;
a.display();
return 0;
}
Why does initialization const int a=9 is not permitted.
But where as if i write constant static int a=9 compiler does not show any error. What is the meaning of writing const static int a=9? when should i write like this ?
~
Use constructor initializer list to initialize non-static constant members.
ISO C++03 says the following things about static data members.
[class.static.data]9.4.2 Static data membersYou can take the address of a static member if (and only if) it has an out-of-class definition: