Re: Modifying through pointer-to-const
From: Russell Hanneken (rghanneken_at_pobox.com)
Date: 04/19/04
- Next message: Mike Smith: "Re: Why is OO popular?"
- Previous message: Walter Tross: "Re: Modifying through pointer-to-const"
- In reply to: Dave: "Modifying through pointer-to-const"
- Next in thread: Dan Bloomquist: "Re: Modifying through pointer-to-const"
- Reply: Dan Bloomquist: "Re: Modifying through pointer-to-const"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 19 Apr 2004 21:29:38 GMT
Dave wrote:
>
> In the code below, I am able to modify data through the pointer-to-const
> DynGapRec parameter. The last two lines show this.
> Is there any circumstance where this should be legal, or
> do I definitely have a compiler bug (VC++ 7.1)?
>
> void CInstrProcEngine::AggregateDynamicGapRecords(const CAccount*
> iAcct, const SingleInstr* pInstr,
> const int* evPoints,
> const CGapInt* pGap,
> const DynGap* DynGapRec,
> CDate forecastDate,
> int RateType,
> int startPd,
> int endPd)
> {
[. . .]
> DynGaRec->MvPeriod[index] = currentEvPt; // ILLEGAL!!!
> DynGapRec->GapInteval[index] = pGap->i_GapEndMt[gapRecCnt]; //
> ILLEGAL!!!
Dave,
This would be legal if MvPeriod and GapInteval are pointers to non-const
data. Assuming this is the case, you're changing the values of data being
pointed to, not the values of the pointers per se. Since the pointers are
members of DynGap, and the data being pointed to are not, the assignments
don't affect the state of DynGapRec (as far as the compiler is concerned,
anyway).
If this is not what you want, you might consider hiding MvPeriod and
GapInterval, and providing non-const member functions to alter the data they
point to.
-- Russell Hanneken rghanneken@pobox.com Remove the 'g' from my address to send me mail.
- Next message: Mike Smith: "Re: Why is OO popular?"
- Previous message: Walter Tross: "Re: Modifying through pointer-to-const"
- In reply to: Dave: "Modifying through pointer-to-const"
- Next in thread: Dan Bloomquist: "Re: Modifying through pointer-to-const"
- Reply: Dan Bloomquist: "Re: Modifying through pointer-to-const"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|