On Feb 22, 2007, at 7:34 PM, Red Marble Games wrote: Well, OK, here's one, and I don't know if this is a C++ issue or an Xcode issue. It seems that if I derive a templated class from a templated class, then Xcode doesn't let me refer to inherited members of the parent class without a prefix. As a trivial (and very incomplete) example, just to illustrate:
template <class T> class foo { protected: OSStatus SetUpRenderStates(); };
template <class T> class bar : public foo<T> { public: OSStatus Render(){ SetUpRenderStates(); }; <<--NOPE };
In the example above, my "bar" class can't include a call to SetUpRenderStates; Xcode complains that there is no definition of that function. Instead, bar's Render() function must say "foo<T>::SetUpRenderStates();" to get a compile. I'm working on a port, and the code compiles fine without the prefix on the John Hodgman OS (and CodeWarrior also liked it fine on the Mac). Is there something to be done other than going through all the derived classes and adding all these prefixes?
Mark, That's no bug, that's a feature. As people have gotten used to working with templates, they have discovered that some things just didn't add up. There could be a specialization of foo that doesn't have the SetUpRenderStates() function at all. There is no way for the compiler to know that (or it would be way too hard and slow) at instantiation time. So, they added this error so that you would see it at compile time.
To fix it, you still need a prefix. You have to add "this->" in front of the function call. Since "this" depends on a template parameter, the compiler can figure things out and knows the code is acceptable.
So, it isn't really an issue. Any modern C++ compiler should emit this error. CodeWarrior is now defunct and doesn't qualify anymore. I don't know about the latest MS compilers. The last time I checked, VS.Net 2003 still had serious problems. I haven't checked the 2005 editions. C++ really isn't their focus anymore.
John
|