• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Templates question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Templates question


  • Subject: Re: Templates question
  • From: John Daniel <email@hidden>
  • Date: Thu, 22 Feb 2007 20:05:58 -0600

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

 _______________________________________________
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

  • Follow-Ups:
    • How to Fix Warning Message?
      • From: Dave <email@hidden>
    • Re: Templates question
      • From: John Mikros <email@hidden>
References: 
 >Templates question (From: Red Marble Games <email@hidden>)

  • Prev by Date: Templates question
  • Next by Date: Re: Templates question
  • Previous by thread: Templates question
  • Next by thread: Re: Templates question
  • Index(es):
    • Date
    • Thread