# VC2005 b2, Managed C++, Global managed class?

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

## Recommended Posts

I'm somewhat new to managed C++, but I've been figuring it out relitively well, figuring out how to make the darn thing work on my own, even when there are times when I want to do one thing (like initialize a value on the gcheap) I can at least figure out a workaround (create on gcheap, then assign). However, I can't figure out a workaround for this. What I want to do is:
ref class MyClass
{
public:
MyClass(int i);
};
const MyClass Hiall(1);
void Func()
{
Use(Hiall);
}


But the compiler complains of "Global or static variable may not have managed type." The only way to make it work is:
ref class Globals
{
static const MyClass Hiall = MyClass(1);
};
void Func()
{
Use(Globals::Hiall);
}


However, I have no way of extending the "Globals" class without going in and editing it directly (so I can't have "Globals" in "Party.h" and "Globals" in "Objects_Base.h", and making a specially named one is really unweildy). I also have to specify the class first. That actually defeats the entire purpose of the globals I'm using. Is there any way to get past this restriction on managed C++? "using namespace Globals" or "using ref class Globals" doesn't work. I can't typedef it. The best I can think of is macro it, and that just seems like a few thousand steps backward for this scenario.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633303
• Total Posts
3011280
• ### Who's Online (See full list)

There are no registered users currently online

×