S
Suneel VLN
Hi all,
Below example is the from the famous C++ book "Thinking in C++, Vol
1".
#include <iostream>
using namespace std;
int x = 100;
class WithStatic
{
static int x;
static int y;
public:
void print() const
{
cout << "WithStatic::x = " << x << endl;
cout << "WithStatic::y = " << y << endl;
}
};
int WithStatic::y = x + 1;
int WithStatic::x = 51;
int main()
{
WithStatic ws;
ws.print();
}
Output is...
WithStatic::x = 51
WithStatic::y = 52
My questions are...
1. Why local x took precedence over global x?
2. Even though local x initialized after local y initialization, how x
value updated when initializing y?
Can anybody explain me this behavior?
Thanks in advance.
--Suneel VLN.
Below example is the from the famous C++ book "Thinking in C++, Vol
1".
#include <iostream>
using namespace std;
int x = 100;
class WithStatic
{
static int x;
static int y;
public:
void print() const
{
cout << "WithStatic::x = " << x << endl;
cout << "WithStatic::y = " << y << endl;
}
};
int WithStatic::y = x + 1;
int WithStatic::x = 51;
int main()
{
WithStatic ws;
ws.print();
}
Output is...
WithStatic::x = 51
WithStatic::y = 52
My questions are...
1. Why local x took precedence over global x?
2. Even though local x initialized after local y initialization, how x
value updated when initializing y?
Can anybody explain me this behavior?
Thanks in advance.
--Suneel VLN.