__gc and __nogc ???

C

Chris

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
 
B

Ben Schwehn

T

Tomas Restrepo \(MVP\)

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;
}
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top