So when I pass my string to the dataLength function, the compiler
could conceivable choose one of three implementations. The first
function should return 4: the size of a pointer (assuming you are
compiling in 32-bit mode). The second should return 1 (the size of
the char being pointed to). The third should return 13 (the length
of the string). What gcc gives me is:
Case 1: 13
Case 2: 4
Having an intermediary class, then, was the source of my grief. On
further examination, I determined that if I remove the "<T>" from the
line "return AccessFunctions::dataLength<T>(value);", case 2 would
also return 13. Is there something illegal/deprecated about the way
I had it? If so, it would have been nice to get a compiler warning.
I vaguely recall having to put that in there to assuage some ancient
compiler (FWIW, CW 10 doesn't seem to care one way or the other). I
am lazy, and wouldn't have added it without reason. :-)
Anyway, so that's one down, at least...
-Ted
On Aug 28, 2006, at 8:11 PM, Steve Checkoway wrote:
On Aug 28, 2006, at 1:00 PM, Edward K. Chew wrote:
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.
As you can see, the general version will be called for char*.
Personally, I can never remember the matching rules so I always
have to test this stuff out.
--
Steve Checkoway
_______________________________________________
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