473,809 Members | 2,687 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Global visibility with Managed types

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
Nov 17 '05 #1
7 1506
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

Nov 17 '05 #2
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


Nov 17 '05 #3
Steve,
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.


The same way you'd give visibility of any type to a function in another
module.... a header file!

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #4
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



Nov 17 '05 #5
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
>>
>>
>
>



Nov 17 '05 #6
I get what you mean. It is so obvious thing that we miss to mention it very
often. (and often assume that you guys would understands our lingo)
aclass *myclass=new aclass();


You dont have to create an object at all. You can access them using
"aclass::gv ar". "::" is called scope resolution operator.

so the code would be
void test(void)
{
aclass::gvar = 100;
}

void test2(void)
{
aclass::gvar += 200; // += means aclass::gvar = aclass::gvar + 200.
Another C++ stuff
}

I guess, you will have to learn a lot C++ concepts before you could jump
into managed C++. Pick up a good book on C++.
Nov 17 '05 #7
Thanks again Ashok

Now I understand. I am just reading through managed C++ and .NET devleopment
and after your last post have found the section on static member methods.

Steve

"Ashok K Kumar" <As*********@di scussions.micro soft.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
I get what you mean. It is so obvious thing that we miss to mention it very
often. (and often assume that you guys would understands our lingo)
aclass *myclass=new aclass();


You dont have to create an object at all. You can access them using
"aclass::gv ar". "::" is called scope resolution operator.

so the code would be
void test(void)
{
aclass::gvar = 100;
}

void test2(void)
{
aclass::gvar += 200; // += means aclass::gvar = aclass::gvar + 200.
Another C++ stuff
}

I guess, you will have to learn a lot C++ concepts before you could jump
into managed C++. Pick up a good book on C++.

Nov 17 '05 #8

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

Similar topics

7
2458
by: Ekim | last post by:
hello, I'm using MANAGED C++ and need one of the following two questions answered: 1.) How can one make a global managed array? I'm thinking on something like defining static System::Byte globalArray __gc; at the begin of a file. But I get the error "global Array: cannot declare a global or static managed type object or a __gc pointer"
6
3951
by: Soha | last post by:
I'm a beginner in using javascript and i need a reply so urgent; i have a problem in using javascript with asp the problem is that i want to define a global variable and then change the value of it after clicking on a link which activate a function that changes the global variable. this variable i use as the value of a hidden field in a form. my problem is that the global variable dosen't change. this is the code i used to do this: ...
7
3148
by: Michael | last post by:
Hi newsgroup, as the subject indicates I am looking for an advice using global variables. I am not if this problem is more about style then C. If its wrong in thi group, sorry. So I have a couple of function that all need the same information (all located in the same file). By now it looks like /* file beginns */
2
1692
by: Abdessamad Belangour | last post by:
Hi all, and thanks for previous answers (especially Nicholas Paldino) An assembly is composed of a set of modules. The module class has a method for reading global methods GetMethods(). My questions are : 1. Are we obliged to go down to modules for reading global methods? 2. What about the GetExportedTypes() method of an assembly class ? 3. Should we ignore global methods as we are C# users (not C++) and that we are interested in...
3
6197
by: Dave | last post by:
I'm at a point where I would really like to focus in on learning .NET but am having a hard time deciding which language to use. I learned to program in C++ but have spent quite a bit of time using VB6. I need to get started on developing a new application and would like to know what the advantages are of using managed C++ .NET over VB.NET or C#? My application will involve some, data acquisition, storage, data plotting, statistical...
4
5724
by: William F. Kinsley | last post by:
My understanding is that when I re-compile a existing MFC application with the /clr switch, that the code generated is managed(with some exceptions) but that the data isn't, i.e. not garbage collected. I also noticed that when replaced some of the existing MFC dialogs with managed winforms that everything is still running in the same app domain.( No context change) So my question is this, what are the performance differences in using...
3
4203
by: Peter Oliphant | last post by:
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...
3
1555
by: Rodrigo Juarez | last post by:
Hi Microsoft Visual Studio 2005, Visual Basic and winforms application I need a global error handler, where should I put that. Any examples? TIA Rodrigo Juarez
112
5499
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions that may print some messages. foo(...) { if (!silent)
0
10639
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10383
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7661
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.