Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gcc 4 const confusion



On 28.05.2005 04:16, "Scott Lahteine" <email@hidden> wrote:

>      virtual void InsertCopyBefore(UInt16 index, const T** elemPtr,
> UInt16 count=1)
<...>
>      inline void InsertCopyBefore(UInt16 index, const TObjectArray<T>
> &src) { InsertCopyBefore(index, src.m_array, src.Size()); }
> 
> 
> The last method is the one that gets the error in gcc4:
> 
> TArray.h:418: error: invalid conversion from 'FPChordGroup** const'
> to 'const FPChordGroup**'
> TArray.h:418: error:   initializing argument 2 of 'void
> TObjectArray<T>::InsertCopyBefore(UInt16, const T**, UInt16) [with T
> = FPChordGroup]'
> 
> 
> But I'm probably misunderstanding the concept of constness in some way.

  The issue here is that a pointer to a const object is different from a
const pointer to an object (or from a const pointer to a const object). You
are trying to pass a const pointer as a pointer to a const object, and the
compiler rightfully complains.

> What changes can I make to my code so that this error won't occur and
> yet maintain the const-ness of that argument?

  Without knowing more about the architecture of your application, I'd say
that the best approach would be to use STL rather than a custom container. A
few days ago, the options were discussed on this list (search for a message
from Howard Hinnant).

  As an immediate fix, you may try to declare m_array mutable.

- WBR, Alexey Proskuryakov


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to email@hidden

References: 
 >gcc 4 const confusion (From: Scott Lahteine <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.