• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
gcc 4 const confusion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gcc 4 const confusion


  • Subject: gcc 4 const confusion
  • From: Scott Lahteine <email@hidden>
  • Date: Fri, 27 May 2005 17:16:48 -0700

Hi,

I just upgraded to XCode 2 / gcc 4 and I'm trying to get my code up to spec for the new compiler. I'm getting an error related to 'const' and I'm not sure what changes I need to fix it.

In particular, I have a template class called TObjectArray that extends my TArray template class. The difference between TObjectArray and TArray is that TObjectArray stores instance *pointers* and acts as their primary storage. I built this class so that as the array is resized there is no need to relocate instance data, and as items are added/removed they get constructed/deconstructed properly. Anyhow, I have a set of methods that looks like this:

virtual void InsertCopyBefore(UInt16 index, const T** elemPtr, UInt16 count=1)
{
if (count) {
ExpandOrContract(index, count, true);
ConstructCopies(elemPtr, &TArray<T*>::m_array[index], count);
}
}


inline void InsertCopyBefore(UInt16 index, const T* element) { InsertCopyBefore(index, &element); }
inline void InsertCopyBefore(UInt16 index, const T& elemRef) { const T* temp = &elemRef; InsertCopyBefore(index, &temp); }
inline void InsertCopyBefore(UInt16 index, TObjectArray<T> &src) { InsertCopyBefore(index, src.m_array, src.Size()); }
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]'



I can remove 'const' from the front of the &src argument and the error goes away. The thing is, I want the source array (argument 2) to be const to reassure the compiler that no changes will be made to that array. But I'm probably misunderstanding the concept of const- ness in some way.


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

(Or would I save a lot of headaches by just using a subclass of std::vector?)

--
  Scott Lahteine
  Thinkyhead Software

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: gcc 4 const confusion
      • From: Alexey Proskuryakov <email@hidden>
  • Prev by Date: Sorting groups?
  • Next by Date: autoconf and xcode
  • Previous by thread: Re: Sorting groups?
  • Next by thread: Re: gcc 4 const confusion
  • Index(es):
    • Date
    • Thread