473,799 Members | 3,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

__gc and Array

#pragma once

using namespace System;

__gc class CWords

{

public:

CWords(void);

~CWords(void);
int iPassedItems[1000];

};

How to add array of integers to my class?

int iPassedItems[1000]; - makes error :

error C2697: 'iPassedItems' : must explicitly specify __gc or __nogc for an
array declared in a managed type

I know, that I have to use __gc in my array, but I don't know how to use it.

Please Help

Nov 17 '05 #1
6 3335
"Lupina" <lu****@op.pl > wrote in message
news:Oz******** ******@TK2MSFTN GP10.phx.gbl...
How to add array of integers to my class?

int iPassedItems[1000]; - makes error :

error C2697: 'iPassedItems' : must explicitly specify __gc or __nogc for an array declared in a managed type

I know, that I have to use __gc in my array, but I don't know how to use it.


This declares an array whose elements are of the managed Object class:

Object *parms __gc [];

This allocates an array of n elements:
parms = new Object * __gc [n];

Regards,
Will
Nov 17 '05 #2
Hi Lupina,
You could use something like

#pragma once

using namespace System;

__gc class CWords
{

public:

CWords(void){}

~CWords(void){}

static int iPassedItems __gc[] = new int __gc[1000];
};

In case you want to initialize a member inside a class it must be static.
Thanks,
Kapil

"Lupina" wrote:
#pragma once

using namespace System;

__gc class CWords

{

public:

CWords(void);

~CWords(void);
int iPassedItems[1000];

};

How to add array of integers to my class?

int iPassedItems[1000]; - makes error :

error C2697: 'iPassedItems' : must explicitly specify __gc or __nogc for an
array declared in a managed type

I know, that I have to use __gc in my array, but I don't know how to use it.

Please Help

Nov 17 '05 #3
Hi Will

I did it acording your hint

__gc class CWords

{

public:

CWords(void);

~CWords(void);

int iPassedItems __gc[];

};

CWords::CWords( void)
{

iPassedItems = new int * __gc [100];

}

but, I got error :

error C2691: 'int __gc *' : invalid type for __gc array element

:(
Nov 17 '05 #4
"Lupina" <lu****@op.pl > wrote in message
news:uk******** ******@TK2MSFTN GP12.phx.gbl...
I did it acording your hint

__gc class CWords

{

public:

CWords(void);

~CWords(void);

int iPassedItems __gc[];

};

CWords::CWords( void)
{

iPassedItems = new int * __gc [100];

}

but, I got error :

error C2691: 'int __gc *' : invalid type for __gc array element

:(


I showed you how to create an array of managed, heap-based,
garbage-collected objects. An integer is a "value" (loosely: stack based)
type. You don't need special syntax.

Change

int iPassedItems __gc[];

to

int *iPassedItems;

Change

iPassedItems = new int * __gc [100];

to

iPassedItems = new int[100];

Regards,
Will
Nov 17 '05 #5
It's working at last. I wasn't able to advise myself with it.
Both versions are operating now (Will, Kapil).

Great Thanks
Nov 17 '05 #6
I still have the question, conected indirectly with previous.

I've created a class in which I want to keep global date (available in a few
forms).

The object of this class I have in the main form :
#pragma once

#include "Words.h"
#include "DialogOptions. h"

namespace Aplication
{
....

public __gc class Form1 : public System::Windows ::Forms::Form
{
public:
Form1(void)
{
InitializeCompo nent();
myCWords = new CWords();
dlgOptions = new DialogOptions() ;

}
....
public : CWords *myCWords;
public : DialogOptions *dlgOptions;
....

now in the other form (eg: DialogOptions) in the top of DialogOptions.h ,
when I add

#include "Form1.h"

I recieve an error :
Form1.h(47): warning C4677: 'myCWords': signature of non-private function
contains assembly private type 'CWords'

How to refer to the first form (from second)?
Nov 17 '05 #7

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

Similar topics

2
1568
by: Robert A Riedel | last post by:
This is a repost of a question that received no answer. In a module DATA.CPP, when attempting to initialize a __gc array as follows: // // Begin sample ... // // // Yes, I include all of the correct assemblies, including MSCORLIB.DLL and all of // the other .NET related paraphernalia.
1
1492
by: TGF | last post by:
Hello, I am calling a Filestream::Read() (i.e. fs->Read(arg1, arg2, arg3)). The problem is I have a pointer to an unsigned char block of memory and would like to fill it with the call to 'Read'. However the FileStream::Read function only takes a Byte __gc argument. I tried the following Byte __gc *bytePtr = bufferPtr;
1
1536
by: Paul Steckler | last post by:
I'm using a managed C++ class that wants an unsigned char __gc as input. Is there a way to easily populate that array from a string constant (or wide string constant, etc.)? I'd like to do something like: unsigned char foo __gc = "your ad here"; but of course that doesn't work.
1
1609
by: Bern McCarty | last post by:
I am using MEC++ in VC 7.1. I had a method on a __gc object that looked like this: __property System::UInt32 get_MyProperty(void) { System::Byte __pin * pinBytes = &m_byteArray; // entire array is now pinned NativeStruct const __nogc* nativeStructP = reinterpret_cast<NativeStruct const __nogc*>(pinBytes);
2
2571
by: microsoft | last post by:
Hi All, I am fairly new to Managed C++ extensions. I started trying to implement a interface defined in a C# project, in C++. The problem was with passing value arrays from c# to c++. I found examples on the web which worked, but found mine didn't. After narrowing down the interface I found what I believe to be the problem. The order of the parameters! The code below shows the function that does not compile named QueryPositionsForward....
4
1174
by: TJH | last post by:
hi there im new to develop in .net, and i keep getting this compiler error "cannot perform pointer arithmetic on __gc pointer" when i try: some_object->array = something; Thanks :) Toke Jansen
8
1202
by: Peter Oliphant | last post by:
While it does look like 2005 does use a better syntax in general for garbage collection than 2003, here is something I think went the other way. arrays. Do people really think that: array<MyClass ^> ^ MyArray = gcnew array<MyClass ^>(100); is a better syntax than: MyClass* MyArray __gc = new MyClass* __gc ;
4
6079
by: viks | last post by:
Hi guys I need little help here . I want to convert 'System::Object __gc * array ' to 'float array' Lets say I have object Reader with method Send ,it returns a variant that contains a one-dimensional array of float value . I m trying to do something like this.
0
972
by: John Gardner | last post by:
Hello I've got some managed C++ and I would like to do something like this: Int16 data1 __gc = {1, 2, 3, 4, 5}; Int16 data2 __gc = {2,3,4,5,6}; Int16 bigArr __gc; bigArr->Add(data1); bigArr->Add(data2);
0
9544
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10490
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...
0
10259
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10030
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...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
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
6809
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();...
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
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.