Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

allocate memory!!!

Status
Not open for further replies.

jayjay60

Programmer
Jun 19, 2001
97
0
0
FR
I would like to create a function which could return 2 COleDateTime objects simultaneously, so i think that i could use a pointer of COleDateTime. But, as i'm a beginner in C++, i would like to know if someone could show me how we could do the allocation of this pointer, his deletion, and how i could return the dates, as i want the function return dates?

thanks in advance

jayjay
 
I think, for allocating space this is enough.

int n = 2;

COleDateTime* pointer = new COleDateTime [n];

to return the pointer, ...
return (pointer);

It may not be correct, try it please! :cool:
 
The above is correct except you can't have the 2 in a variable. It has to be a constant.

COleDateTime* CTestView::GetDates()
{
static COleDateTime pointer[2];

return pointer;
}

I think the above works
 
do you think that when we do this kind of allocation of memory:
COleDateTime* pointer = new COleDateTime [2];
.
.
.
return pointer;
, we needn't of delete this memory space?
 
not if its local.

If you deleted it then the pointer would point to nothing.

If you use something like malloc then you do need to use the free function.
 
i have a little pb with my function. in fact, i do sthg like that:

COleDateTime *pDate=new COleDateTime[2]

pDate[0]=StartDate;
pDate[1]=EndDate;

return pDate;

when i debug my application, in the debug window, i could see the "evolution" of the variable pDate, as it's a COleDateTime, it has 2 part:m_dt and m_status.

i could only see that m_dt take, firstly the value of StartDate, and after not EndDate.

but as i'm a beginner, i don't know if what i wrote above is correct, so if someone could tell me if it's the case.

gerald


 
If you goto the watch window during debug and type:

pDate[0].m_dt
pDate[0].m_status
pDate[1].m_dt
pDate[1].m_status

What do you get?

What data type are StartDate and EndDate?
 
StartDate,endDate are COleDateTime.
i don't see what you show me, i have only pDate.m_dt and pDate.m_status
so?
 
Maybe if you change:

COleDateTime *pDate=new COleDateTime[2]

to:

COleDateTime pDate[2];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top