473,385 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Declaring GLOBAL managed objects

OK. I created a managed class. Now I want to create a global pointer to an
instance of the class that the entire application can reference.

Yet, when I do something like:

MyManagedClass* my_instance ;

as a global variable (i.e., it's not in a process of class or struct, or
etc.) it tells me something like 'managed class instances can't be global'.
That seems pretty restrictive...

What can I do to create global instances of a managed class?

The exact error message is:

error C3145: 'form' : cannot declare a global or static managed type object
or a __gc pointer

for this code:

PAO_Form* form ; // which is not in anything, just part of the .CPP file
that contains main()

[PAO_Form is a __gc class]

Thanx in advance for any help! : )


Nov 17 '05 #1
3 4184
Try gcroot

"Peter Oliphant" <po*******@RoundTripInc.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
OK. I created a managed class. Now I want to create a global pointer to an
instance of the class that the entire application can reference.

Yet, when I do something like:

MyManagedClass* my_instance ;

as a global variable (i.e., it's not in a process of class or struct, or
etc.) it tells me something like 'managed class instances can't be
global'. That seems pretty restrictive...

What can I do to create global instances of a managed class?

The exact error message is:

error C3145: 'form' : cannot declare a global or static managed type
object or a __gc pointer

for this code:

PAO_Form* form ; // which is not in anything, just part of the .CPP file
that contains main()

[PAO_Form is a __gc class]

Thanx in advance for any help! : )

Nov 17 '05 #2

Peter Oliphant wrote:
OK. I created a managed class. Now I want to create a global pointer to an
instance of the class that the entire application can reference.

Yet, when I do something like:

MyManagedClass* my_instance ;

as a global variable (i.e., it's not in a process of class or struct, or
etc.) it tells me something like 'managed class instances can't be global'.
That seems pretty restrictive... Yes and no... It prevents from using some bad designs (such as having
global variables ;-)

What can I do to create global instances of a managed class?


The global should be an unmanaged object referencing the managed object
--> gcroot is what you are looking or.

Arnaud
MVP - VC

Nov 17 '05 #3
Peter Oliphant wrote:
OK. I created a managed class. Now I want to create a global pointer to
an
instance of the class that the entire application can reference.

Yet, when I do something like:

MyManagedClass* my_instance ;

as a global variable (i.e., it's not in a process of class or struct, or
etc.) it tells me something like 'managed class instances can't be
global'.
That seems pretty restrictive...

Yes and no... It prevents from using some bad designs (such as having
global variables ;-)

What can I do to create global instances of a managed class?


You can declare public static member field or property of MyManagedClass*
type on managed class.
E.g.

public __gc class MyManagedClass
{
static MyManagedClass()
{
// Initialize it
my_instance = ...
}
public:
static MyManagedClass *my_instance;
};

--
Vladimir Nesterovsky
e-mail: vl******@nesterovsky-bros.com
home: http://www.nesterovsky-bros.com
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Carlos Ribeiro | last post by:
Hello all, I'm posting this to the list with the intention to form a group of people interested in this type of solution. I'm not going to spam the list with it, unless for occasional and...
1
by: Oystein Haare | last post by:
Note: This might be a bit off topic.. I want to create some global objects that register themselves with another "manager"-class upon creation: class SomeClass { ... }; // cpp:
10
by: Shuo Xiang | last post by:
Greetings: I know that variables declared on a stack definitely does not reside in heap space so there is only a very limited amount of stuff that you can store in the stack of a function. But...
3
by: JJ | last post by:
Hi All, I was wondering if I create an object in public main does it persist for the lifetime of the app? If not where do u create objects that will persist for the lifetime of app so that when...
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
2
by: Craig | last post by:
Hi, I'm having difficulty understanding how the Application_End event in the Global.asax file gets called. I thought that it's called when the specific web site is stopped via the IIS management...
0
by: Chris Joslyn | last post by:
I am integrating some legacy VC++ 6.0 classes into a managed C++.NET Windows service. After I had the basic framework in place and running, I added in the source files I needed and tried to run the...
3
by: Faisal | last post by:
Hi. I'm in the process of moving an application from ASP to ASP.NET, & I'm writing in VB, using VS.NET. I'm new to the .NET framework & have a basic question regarding static objects defined in...
4
by: Leif902 | last post by:
Hi all, I'm working on a little project and have hit a roadblock, I'm trying to make an extension for a program who's extension DLL's must return either a double or a null terminating string...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.