SOLVED! (was: C++ Bug. Template container wonky.)
WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?! WHY!?!
WHY won’t this work! WHY!?!
MONTHS this has been holding me up. It looks so damn simple!
If I replace “AtomicType” with just about anything, including std::string, it runs like a charm.
Something is wrong with the fact that it doesn’t know what AtomicType is at compile time. But that’s not a bug in the source.
MONTHS this has been holding me up.
ANYBODY!?!
*bangs head on desk*
UPDATE:w00t! Here we go: “While trying to show that it didn’t matter if I instantiated the damn thing” hmmpf…
Seriously though. I added 2 lines to main to create a Bar with an int template, then to call “foobar()” on that object.
While that worked fine and didn’t have anything to do with the problem, it DID give the compiler enough information to give me a more detailed error message (which is a g++ fail IMNSHO.)
The error it yielded was:
dependent-name ‘PretendContainer::InternalType’ is parsed as a non-type, but instantiation yields a type
scrapyard.cpp:21: note: say ‘typename PretendContainer::InternalType’ if a type is meant
Now that makes perfect sense. So changing the offending line to:
typename PretendContainer<AtomicType>::InternalType i;
fixes everything.
So it seems that while everything I was doing was right and legal, the compiler was experiencing a bit too much indirection to adequately intuit what I meant, so it needed the “hint” of an explicit “typename” modifier.
Makes sense, though I can’t say as I’ve ever run in to this before. It’s JUST odd enough that it’s been outside my experience. Which is pretty odd because I’ve seen (and pumped out) a LOT of c++ code in my day.
So now my night is committed to my C++ Unit Testing Library.
(and maybe some WoW)
Tags: C++, Programming, TDD