Re: Template of interface?

From: Shezan Baig (shezanbaig2004_at_gmail.com)
Date: 02/27/05


Date: 26 Feb 2005 17:35:07 -0800


bonj wrote:
> Hello
> How do I declare a template class such that the template class T must
> implement a certain interface?
>
> e.g.
> interface IProvideID
> {
> int MyID;
> };
>
> template<type T>
> class ListOfIDs
> {
> public int add(T& newitem)
> {
> return newitem.MyID; //(this is what I want to do)
> }
> };

You already did it. If the 'T' type does not have a 'MyID' member,
then ListOfIDs<T>::add(...) will fail to compile.

-shez-



Relevant Pages

  • Re: Template of interface?
    ... bonj wrote: ... > How do I declare a template class such that the template class T must ... > interface IProvideID ...
    (microsoft.public.vc.language)
  • Template of interface?
    ... How do I declare a template class such that the template class T must ... interface IProvideID ... class ListOfIDs ...
    (microsoft.public.vc.language)
  • Template of interface?
    ... How do I declare a template class such that the template class T must ... interface IProvideID ... class ListOfIDs ...
    (comp.lang.cpp)
  • Re: Message Mapping for a template class
    ... > Does anyone know how to map messages for a template class? ... For even more fun ... ... declare some of the classes involved in a namespace! ...
    (microsoft.public.vc.mfc)
  • Self-referencing templates
    ... I'm having a time wrapping my mind around how this should work. ... I have a template class that has a list of objects of another class. ... What's the correct way to declare that? ... template class TClientHandler; // supposed to be a forward declaration ...
    (comp.lang.cpp)

Loading