C++ Programming - Is static the problem?
#include < iostream >
using namespace std;
static int i;
class x {
int i;
public:
x() { cout << "In HERE" << endl; }
int geti() { return i; }
};
int main()
{
cout << "Inside main() = " << ((x *)(&i+1))->geti() << endl;
*(&i+1) = 17;
cout << "Inside main() = " << ((x *)(&i+1))->geti() << endl;
static x aa;
cout << "Inside f() : " << aa.geti() << endl;
x bb;
}
When we ran this on Intel Platform Linux (gcc 3.4.3 20041212, Red Hat 3.4.3-9.EL4) & Windows (.NET 2003) the results were very surprising (fcoz will be ;) but on Solaris it worked fine.
Could you guess what was the output on Intel Linux and Windows?
Labels: C++
About this entry
You’re currently reading “
- Published:
- 9:05 am
- by -
1 Comments (Post a Comment)