First question:-
why this is must have to be defined static data members outside of the class and why not this same concept follows in static constant data members?
Example for static data members:-
#include<iostream>
using namespace std;
class game
{
static int num;
int i;
public:
void foo()
{
cout<<endl<<num<<endl;
}
};
int game::num=0;
int main()
{
game g;
g.foo();
return(0);
}
Example for static constant data members:-
#include<iostream>
using namespace std;
class game
{
static const int num;
int i;
public:
void foo()
{
cout<<endl<<num<<endl;
}
};
int game::num=0; \\error why ?
int main()
{
game g;
g.foo();
return(0);
}
second question:-
Static constant data members initialization is allowed only for integral types why not for strings ?
#include<iostream>
using namespace std;
class game
{
static const char name[10]="vikas"; \\ error why ?
int i;
public:
void foo()
{
cout<<endl<<name<<endl;
}
};
int main()
{
game g;
g.foo();
return(0);
}