Re: Template of interface?
From: Shezan Baig (shezanbaig2004_at_gmail.com)
Date: 02/27/05
- Next message: Matt Bitten: "Re: Exceptions: Bad Design?"
- Previous message: Richard Cavell: "Re: sizeof(int)"
- In reply to: bonj: "Template of interface?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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-
- Next message: Matt Bitten: "Re: Exceptions: Bad Design?"
- Previous message: Richard Cavell: "Re: sizeof(int)"
- In reply to: bonj: "Template of interface?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
Loading