Static member variables

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an MFC Extension DLL that I have flicked the /clr switch on and made a
few other tweaks so it compiles and runs in a managed MFC applicaiton.

The DLL contains a number of classes which contain static member variables
and static methods. Are these permitted in a managed DLL?

Thanks

Colin
 
Colin... All I can say is that MSIL understands static (class) methods and
variables so that you can certainly declare and use static member methods and
variables in a purely managed language as C#. C# does not support static
local variables. I don't (yet) have any C++/cli code for this so this is C#:

class TestStatic
{
// static stuff
private static int uniqueID= 0;
private static int GetUniqueID()
{
lock(typeof(TestStatic))
{
return uniqueID++; // returns zero at start
}
}

// member stuff
private int identity;
public TestStatic()
{
this.identity= TestStatic.GetUniqueID();
}
public int Identity
{
get
{
return identity;
}
}
}
 
I have done quite a lot with /clr so far, and I have not seen problems with
static member variables of native types so far.

Marcus Heege
 
Back
Top