Jump to content
  • Advertisement
Sign in to follow this  
kustom

[.net] Global Variables in C++/CLI

This topic is 4481 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi to all, Im learning to code in C++/CLI for giving support to my native C++ applications to .NET framework and i have a problem: i cant declare a global variable in my .cpp /clr of type .NET like: MyClass^ instance = gcnew MyClass(); i can declare it like local object inside a function but not as global :( May exist a especial form of declarate globals? or maybe it doesnt exist globals? im confused..................... Kustom

Share this post


Link to post
Share on other sites
Advertisement
There are no global variables or functions in C#. But you can use static methods/properties/fields inside a static class instead.


public static class MyGlobalClass
{
public static int MyGlobalField1 = 0;

//or use a static property

private static int myGlobalField2 = 0;

public static int MyGlobalField2
{
get { return this.myGlobalField2; }
set { this.myGlobalField2 = value; }
}
}

// use them like:
void SomeMethod()
{
MyGlobalClass.MyGlobalField1 = 3;
MyGlobalClass.MyGlobalField2 = 5;
}


Share this post


Link to post
Share on other sites
Thanks Zubspace,

I think your code will be easy to write in C++/CLI instead C#

regards

Kustom

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!