Declaring a const variable outside the class ??? Why and How
class A
{
const int a;
a=5;/////////// error
static const int b =6 ; running
}
now here we can see that const int may causes error in some compiler because
const variable specifies whether a variable is modifiable or not. But initializing anywhere other than constructor causes default initialization followed by assignment...
so a is a const and you can't assign value to it....
Now question is that how can you define a const variable outside the class:::
here you can do that
A():a(5)
{
}
whenever constructor is called value of a is initialized by 5
Now question is that how can you define a const variable outside the class:::
here you can do that
A():a(5)
{
}
whenever constructor is called value of a is initialized by 5
nice start good..
ReplyDeleteneed more..
thanx Rajendra, I hope you will continue with my blog for more improvement plz comment on articles.....................
Delete