Overriding multiple inherited templated functions with specialized versions?

Yes, you can make this work: include using namespace std; template class Base { public: virtual void my_callback() = 0; }; class Derived1 : public Base, public Base { public: void Base::my_callback() { cout my_callback(); i_f->my_callback(); } { Derived2 d; Base * i_p = &d; Base * i_f = &d; i_p->my_callback(); i_f->my_callback(); } } Output: Int callback for Derived1. Float callback for Derived Int callback for Derived2. Float callback for Derived2.

Yes, you can make this work: #include using namespace std; template class Base { public: virtual void my_callback() = 0; }; class Derived1 : public Base, public Base { public: void Base::my_callback() { cout my_callback(); i_f->my_callback(); } { Derived2 d; Base * i_p = &d; Base * i_f = &d; i_p->my_callback(); i_f->my_callback(); } } Output: Int callback for Derived1. Float callback for Derived Int callback for Derived2. Float callback for Derived2.

This does not compile (gcc). Your declarations of Derived::my_callback can not work like that. – frunsi Dec 13 '09 at 20:58 This works for me; of note, I am using Visual Studio 2008, which I know has some features that aren't standard.

Thanks! – Narfanator Dec 13 '09 at 21:39 Yeah, this is a side-effect of support for explicit interface implementation. You'll be okay as long as you can stick with MSVC.

– Hans Passant Dec 13 '09 at 21:57.

What you want is not possible. You could add template specializations, though I do not know if this really helps: template class Base { public: virtual void my_callback() = 0; }; template class Base { public: virtual void my_callback() { cout my_callback(); i_f->my_callback(); } { Derived2 d; Base * i_p = &d; Base * i_f = &d; i_p->my_callback(); i_f->my_callback(); } } Output: Base::my_callback() Base::my_callback() Derived2::my_callback() Derived2::my_callback() Let me try to explain why: Derived1 d; Base * i_p = &d; Base * i_f = &d; // will check the vtable, and will call // either Derived1::my_callback // OR Base::my_callback i_p->my_callback(); // will check the vtable, and will call // either Derived1::my_callback // OR Base::my_callback i_f->my_callback(); Though through the vtable there are two versions of my_callback() in class Derived1, you CAN NOT override either of them, you can only override both at once (like Derived2 does in the example)! You should just provide two methods "my_callback1()" and "my_callback2()".

You have to choose your side, either the static, or the dynamic one.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions