Ashok
Thanks again for reply abd your attempts to explain this but I still don't
understand nor can I get this to work with some test code. I must be missing
something as a lonstanding C programmer but newbie managed C++ programmer.
I understand you need to include the header file to see the definition of a
class. That's not what I want. I want to see the actual class throughout the
module. I understand the static int in the class will retain its value, its
how do I see the class I have declared. So in C
int gvar;
void test(void)
{
gvar=100;
}
void test2(void)
{
gvar=gvar+200;
}
This all works as gvar is global but in managed C++
#using <mscorlib.dll >
__gc class aclass
{
public:
static int gvar;
};
void test(void)
{
aclass *myclass=new aclass();
myclass->gvar=100; // This is fine
}
void test2(void)
{
myclass->gvar=myclass->gvar+200; // test2 doesnt know myclass beacuse
not global
}
and I can't declare myclass as global as its a managed type.
So how does test2 see myclass without having to pass it as a a parameter
Thanks
Steve
"Ashok K Kumar" <As*********@di scussions.micro soft.com> wrote in message
news:uh******** ******@TK2MSFTN GP12.phx.gbl...
If you have a int variable as global as follows in C
int iValue;
in C++ terms
//in the .h file
Class CGlobal // or any name
{
public:
static int iValue;
};
//in the .cpp file
int CGlobal::iValue = 100; // or initialize to some thing else in
necessary.
Include the .h file whereever you need to access the global value.
--
------------------------------
Ashok K Kumar
------------------------------
"Steve Marsden" <st***@conquest .ltd.uk> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. .. Ashok
Thanks for the reply. I can see how this preserves the value of the data
members but how does this give visibilty of the class to other functions
in the module.
Thansk
Steve
"Ashok K Kumar" <As*********@di scussions.micro soft.com> wrote in message
news:eE******** ******@TK2MSFTN GP11.phx.gbl... > Declare a class with static data members.
>
> --
> ------------------------------
> Ashok K Kumar
> ------------------------------
> "Steve Marsden" <st***@conquest .ltd.uk> wrote in message
> news:ec******** ******@TK2MSFTN GP14.phx.gbl...
>> Hi
>>
>> As a C programmer just starting to look at Managed C++, I was shocked to >> find that you cannot declare a managed type globally so that for example > in
>> a partiuclar module you can declare some data globally so that all
> functions
>> in that module can see it to save passing it about as parameters.
>>
>> How do you achieve the same thing with Managed C++ managed data.
>>
>> Thanks
>>
>> Steve
>>
>>
>
>