hi,
i have class A ,B and D.
A class header file has a variable with static scope. Inside C and B the same name variable is defined with extern scope. When i run these objects inside the main function it doesnt change the data of that variable accept class D.
here are the class A.h and .cpp
Code:#pragma once static int iTheBad; class A { public: A(void); ~A(void); }; A::A(void) { iTheBad=19; } A::~A(void) { }
here its class B
Code:#include "A.h" extern int iTheBad; #pragma once class B { public: B(void); ~B(void); }; B::B(void) { iTheBad=32; } B::~B(void) { }
here is the D class
Code:#include "A.h" extern int iTheBad; #pragma once class D { public: D(void); ~D(void); }; D::D(void) { iTheBad=1132; } D::~D(void) { }
here is the code, only D class changes the variable while B and A dont change anything ..... Thats really confusing why?????
Code:#include "stdafx.h" #include "A.h" #include "D.h" #include "B.h" int _tmain(int argc, _TCHAR* argv[]) { extern int iTheBad; // iTheBad=0; A Obj1; D Obj3; //it works perfectly and change the variable to 1132 B Obj2; return 0; }




Reply With Quote