Click here to Skip to main content
16,006,827 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: allocate memory Pin
Gérald Mercet13-Sep-01 5:56
Gérald Mercet13-Sep-01 5:56 
GeneralRe: allocate memory Pin
Steen Krogsgaard13-Sep-01 21:20
Steen Krogsgaard13-Sep-01 21:20 
GeneralRe: allocate memory Pin
Gérald Mercet13-Sep-01 22:51
Gérald Mercet13-Sep-01 22:51 
GeneralRe: allocate memory Pin
Steen Krogsgaard13-Sep-01 23:00
Steen Krogsgaard13-Sep-01 23:00 
GeneralRe: allocate memory Pin
Gérald Mercet13-Sep-01 23:39
Gérald Mercet13-Sep-01 23:39 
GeneralRe: allocate memory Pin
Steen Krogsgaard13-Sep-01 23:48
Steen Krogsgaard13-Sep-01 23:48 
GeneralRe: allocate memory Pin
Gérald Mercet14-Sep-01 2:37
Gérald Mercet14-Sep-01 2:37 
GeneralRe: allocate memory Pin
Steen Krogsgaard14-Sep-01 2:53
Steen Krogsgaard14-Sep-01 2:53 
Ahh, let me see if I get this correct.

You have two dates, StartDate and EndDate. You want to calculate how many periods there is between the two dates, but first you have to modify the two dates in some way. When you have calculated the number of periods you don't need the modified dates anymore. Right?

If so, I would forget all about member variables. Do it this way:
void CMyClass::ModifyDates(COleDateTime* pDates)
{
   // pDates points to an array of two dates, pDates[0] and pDates[1]
   // do whatever modification is needed.
}

int CMyClass::CalcNumberOfPeriod(COleDateTime StartDate COleDateTime EndDate, periodtype dt)
{
   COleDateTime Dates[2];
   Dates[0] = StartDate;
   Dates[1] = EndDate;
   ModifyDates(Dates); // Dates i type COleDateTime*. Dates[0] and Dates[1] is type COleDateTime
   int iPeriods;
   // calculate the number of periods between the dates
   iPeriods = .....
   return iPeriods;
}

Of course, the modified dates are lost when CalcNumberOfPeriod returns as the Dates array is automatic.

Now I can also see why you wanted to allocate the dates in your first posts. One way to do the above using heap allocated objects could be:
COleDateTime* CMyClass::AllocAndModifyDates(COleDateTime date1, COleDateTime date2)
{
   COleDateTime* pDates = new COleDateTime[2];
   pDates[0] = date1;
   pDatse[1] = date2;
   // do the modification
   return pDates;
}

int CMyClass::CalcNumberOfPeriod(COleDateTime StartDate, COleDateTime EndDate, periodtype dt)
{
   COleDateTime* pDates = AllocAndModifyDates(StartDate, EndDate);
   int iPeriods;
   // do the calculation of number of periods
   // now we're done using the dates, let's delete them
   delete[] pDates;
   return iPeriods;
}

Hope I got it right this time.


Cheers
Steen.

"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
GeneralRe: allocate memory Pin
Gérald Mercet14-Sep-01 3:24
Gérald Mercet14-Sep-01 3:24 
GeneralRe: allocate memory Pin
Steen Krogsgaard14-Sep-01 3:27
Steen Krogsgaard14-Sep-01 3:27 
GeneralRe: allocate memory Pin
Gérald Mercet12-Sep-01 4:00
Gérald Mercet12-Sep-01 4:00 
GeneralRe: allocate memory Pin
Steen Krogsgaard12-Sep-01 4:07
Steen Krogsgaard12-Sep-01 4:07 
Questionwhile statement probleam, please help? Pin
Tea CH11-Sep-01 17:31
Tea CH11-Sep-01 17:31 
AnswerRe: while statement probleam, please help? Pin
Christian Graus11-Sep-01 17:47
protectorChristian Graus11-Sep-01 17:47 
GeneralRe: while statement probleam, please help? Pin
Tea CH11-Sep-01 20:19
Tea CH11-Sep-01 20:19 
GeneralRe: while statement probleam, please help? Pin
Christian Graus11-Sep-01 21:53
protectorChristian Graus11-Sep-01 21:53 
GeneralRe: while statement probleam, please help? Pin
11-Sep-01 22:16
suss11-Sep-01 22:16 
GeneralIntresting Question Pin
The_Server11-Sep-01 17:08
The_Server11-Sep-01 17:08 
GeneralRe: Intresting Question Pin
Joaquín M López Muñoz12-Sep-01 0:19
Joaquín M López Muñoz12-Sep-01 0:19 
GeneralWTL CCommandBarCtrl troubles Pin
The Liquid Plumber11-Sep-01 15:37
The Liquid Plumber11-Sep-01 15:37 
GeneralWin32 Console Programming Question Pin
the_grip11-Sep-01 10:30
the_grip11-Sep-01 10:30 
GeneralRe: Win32 Console Programming Question Pin
Joaquín M López Muñoz11-Sep-01 12:09
Joaquín M López Muñoz11-Sep-01 12:09 
GeneralRe: Win32 Console Programming Question Pin
User 988511-Sep-01 12:14
User 988511-Sep-01 12:14 
GeneralSerialize problem Pin
José Luis Sogorb11-Sep-01 9:38
José Luis Sogorb11-Sep-01 9:38 
GeneralRe: Serialize problem Pin
Tomasz Sowinski12-Sep-01 0:48
Tomasz Sowinski12-Sep-01 0:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.