Mailing Lists: Apple Mailing Lists

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

gcc 4 const confusion



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:
http://lists.apple.com/mailman/options/xcode-users/email@hidden

This email sent to 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.