template <class S> class Vector; template <class S> class VectorClosure { public: virtual int exec(Vector<S> &) const { return 0; } }; template <class S> class Vector { public: int apply(const VectorClosure<S> &c) { return c.exec(*this); } }; template <class S> class VectorVector : public VectorClosure<S> { public: virtual int exec(Vector<S> &v) const { return (int)sizeof(v); } }; int main() { Vector<double> u; return u.apply(VectorVector<double>()); }