473,396 Members | 2,068 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,396 software developers and data experts.

__gc and __nogc ???

Hi,

if have a __gc class with a datamember of type : a pointer to a DateTime,
but I get a compiler error :

__gc class Employee
{
public:
DateTime * m_hiringDate; ==> error : cannot declare interior __gc
pointer or
reference as a member of 'class'

Employee(DateTime * hiringDate) {
m_hiringDate = hiringDate;
}
};

so, I declare the pointer and Ctor a follows :

DateTime __nogc * m_hiringDate; ==> OK

Employee(DateTime __nogc * hiringDate) {
m_hiringDate = hiringDate;
}

but then do I get an error when allocating a new Employee

Employee *emp = new Employee(new DateTime(2001,1,1));

==> error : cannot dynamically allocate a value type object with managed
members
on C++ (nogc) heap

How can I make it work ?
What is the proper way do deal with this situation ?

thnx
Chris


Nov 17 '05 #1
3 1547
Chris,

if have a __gc class with a datamember of type : a pointer to a DateTime,
but I get a compiler error :

__gc class Employee
{
public:
DateTime * m_hiringDate; ==> error : cannot declare interior __gc pointer or
reference as a member of 'class'

Employee(DateTime * hiringDate) {
m_hiringDate = hiringDate;
}
};


DateTime is a value type, why are you dealing with it with pointers? Just
store the value directly:

__gc class Employee
{
public:
DateTime m_hiringDate;

Employee(DateTime hiringDate) {
m_hiringDate = hiringDate;
}
};

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #2
> __gc class Employee
{
public:
DateTime * m_hiringDate; ==> error : cannot declare interior __gc

Chris,
you could use

DateTime m_hiringDate;

instead.

http://msdn.microsoft.com/library/de...nsspec_7_4.asp

"Note that although variables with type "__gc pointer to __value class"
point to a whole __value class, they are nevertheless considered
interior pointers; any __value class on the runtime heap must be
embedded within a __gc object."

hth
--
Ben
http://bschwehn.de
Nov 17 '05 #3
Chris,

if have a __gc class with a datamember of type : a pointer to a DateTime,
but I get a compiler error :

__gc class Employee
{
public:
DateTime * m_hiringDate; ==> error : cannot declare interior __gc pointer or
reference as a member of 'class'

Employee(DateTime * hiringDate) {
m_hiringDate = hiringDate;
}
};


DateTime is a value type, why are you dealing with it with pointers? Just
store the value directly:

__gc class Employee
{
public:
DateTime m_hiringDate;

Employee(DateTime hiringDate) {
m_hiringDate = hiringDate;
}
};

--
Tomas Restrepo
to****@mvps.org
Nov 17 '05 #4

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

Similar topics

3
by: NigelW | last post by:
Clarification needed please. If I compile a C++ program with the /clr option inpsection of the resulting assembly with ILDASM shows MSIL even for methods in classes for which I have not...
15
by: Edward Diener | last post by:
Why is it impossible to have a __value class instance variable in a __nogc class when it is possible to have a built-in type instance variable in a __nogc class ? __value class X { int a; };...
3
by: Edward Diener | last post by:
I want to share a __nogc classes between different assemblies. For __gc classes, one only needs to declare the class public in order to be able to do this. Is there a way to share a __nogc class so...
2
by: Gueverson | last post by:
Hello, I am new in programming smart cards and I got an error in compiling that I cannnot manage to get rid of. There is a function in the PCSC that is called "ScardEstablishContext" I am calling...
1
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...
6
by: Lupina | last post by:
#pragma once using namespace System; __gc class CWords { public:
1
by: Chris | last post by:
Hi, if have a __gc class with a datamember of type : a pointer to a DateTime, but I get a compiler error : __gc class Employee { public: DateTime * m_hiringDate; ==> error : cannot...
1
by: Ian Lazarus | last post by:
Hello, I tried to confirm that two different heap allocation calls were being made, i.e., one for __gc and one for __nogc. However, the addresses of the calls (as seen in disassembly) are not...
1
by: Bae,Hyun-jik | last post by:
Is member variable alignment in __gc class same to that of __nogc class? For example, does this code below make problems?(Please ignore other errors such as wrong grammar ,etc.) Please reply....
1
by: Achim Domma (Procoders) | last post by:
Hi, I still try to implement a .Net wrapper to handel AVI Files. I'm unsing managed C++ with VStudio 2003. The structure of my classes looks like this: class AudioStream { ... } class...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
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,...
0
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...
0
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,...

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.