template C++ class to simulate java interface?

I have such a template class
template <class T>
class foo{
// some stuff here
};
How do I make sure that class T has some methods? For example T has to be comparable.
Use pure virtual functions, which you can find somewhere on here:
http://www.parashift.com/c++-faq-lite/

This might also be worth reading:
http://www2.research.att.com/~bs/bs_faq2.html#constraints
Why bother? If the user forgets to write operator== or operator!= it won't compile anyway,
just as it would not compile if you made operator== and/or operator!= pure virtual in a base
class and forgot to override them in a derived class.
jsmith+1

i learned that c++ is not java..
This is actually a part of an interview question.
I thought the same as jsmith did.
The interviewer seemed not satisfied with that answer.
Well... just because they are interviewing you doesn't mean they are a super genius.

Operator overloading and inheritance don't mix well, so I would argue against the
pure virtual approach here. But if T has to have a frobnicate() method, then perhaps
pure virtuals in a base class is the answer (though still I would argue that in itself,
I'd do nothing and let the compiler complain).
Topic archived. No new replies allowed.