Re: Template trouble
Re: Template trouble
- Subject: Re: Template trouble
- From: "Edward K. Chew" <email@hidden>
- Date: Mon, 28 Aug 2006 16:00:53 -0400
Oh, I forgot to mention, I have run into trouble with template
specialization. For example, I have a function along the lines:
template <typename T> UInt32 myHashFunction(T value, int hashBitLength);
I specialized this for C strings:
template <> UInt32 myHashFunction(const char *str, int hashBitLength);
In most cases, I use a string and get the specialized version, but in
a few situations, I get the general implementation instead. I
experimented with partial specialization (i.e. ...myHashFunction
(const T *pointer... ), but it still goes with the general case. The
debugger says that the class from which I call myHashFunction is of
type myClass<char const *>, but I believe "const char *" and "char
const *" are equivalent in C++. Anyway, I tried every permutation I
could think of to no avail.
This sort of nonsense has cost me two days of debugging already, and
it's really starting to drive me nuts. Any help would be appreciated...
Incidentally, I am running Xcode 2.4 gcc 4.0, if I'm not mistaken.
It's a Carbon C++ app.
-Ted
On Aug 28, 2006, at 15:29, Edward K. Chew wrote:
I have been running into a lot of runtime problems bringing a
CodeWarrior C++ project over to Xcode. The most problematic
classes seem to be those where I have a base class with some
virtual methods and a class template deriving from it. If the
template object calls on a base class method which, in turn, calls
a virtual method implemented back in the template, the Xcode
executable sometimes drops the ball and can't find the right
virtual method. (The method dispatch table, when gdb lets me see
it, seems to have an unusually low address in those instances, and
may be pointing to unmapped memory?) This has never occurred in
CodeWarrior, and what is frustrating is that the behaviour in Xcode
can be unpredictable and difficult to reproduce.
For example, I can simply declare a template object somewhere in
main.cp and it messes up the initialization of another object in
another source. The test variable need not use the same template
data type, nor does it even need to be created before the other one
gets initialized. I can't imagine how the one could possibly be
affecting the other, but I'm beginning to think something weird is
going on at link time.
I have also run into problems with STL objects, usually when they
are nested (e.g. a map where each data element is itself a list or
a vector). The iterators seem get lost from time to time.
Unfortunately, I have yet to succeed in coming up with a simple
example which replicates the behaviour. I was wondering if others
have been having these sorts of problems, or if anyone can offer
some advice on what I can check next?
-Ted
_______________________________________________
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