Re: Modifying through pointer-to-const
From: Dan Bloomquist (EXTRApublic20_at_lakeweb.com)
Date: 04/20/04
- Next message: Phlip: "Re: Why is OO popular?"
- Previous message: Fraser Ross: "Re: "static" question"
- In reply to: Russell Hanneken: "Re: Modifying through pointer-to-const"
- Next in thread: Walter Tross: "Re: Modifying through pointer-to-const"
- Reply: Walter Tross: "Re: Modifying through pointer-to-const"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 19 Apr 2004 22:00:11 GMT
Russell Hanneken wrote:
> 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).
I've tested in 7.1 and this is the case. If the member is declared
const, then the compiler will balk.
Best, Dan.
-- http://lakeweb.net http://ReserveAnalyst.com No EXTRA stuff for email.
- Next message: Phlip: "Re: Why is OO popular?"
- Previous message: Fraser Ross: "Re: "static" question"
- In reply to: Russell Hanneken: "Re: Modifying through pointer-to-const"
- Next in thread: Walter Tross: "Re: Modifying through pointer-to-const"
- Reply: Walter Tross: "Re: Modifying through pointer-to-const"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|