#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
William DePalo [MVP VC++] - 10 Jun 2004 17:55 GMT
> How to add array of integers to my class?
>
[quoted text clipped - 4 lines]
>
> 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
Lupina - 10 Jun 2004 18:30 GMT
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
:(
William DePalo [MVP VC++] - 10 Jun 2004 20:02 GMT
> I did it acording your hint
>
[quoted text clipped - 24 lines]
>
> :(
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
Kapil - 10 Jun 2004 18:04 GMT
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
> #pragma once
>
[quoted text clipped - 24 lines]
>
> Please Help
Lupina - 11 Jun 2004 06:38 GMT
It's working at last. I wasn't able to advise myself with it.
Both versions are operating now (Will, Kapil).
Great Thanks
Lupina - 11 Jun 2004 07:15 GMT
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)
{
InitializeComponent();
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)?