473,394 Members | 2,063 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,394 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 1545
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...

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.