
From: David Abrahams <dave@boost-consulting.com>
Rob Stewart <stewart@sig.com> writes:
From: "Reece Dunn" <msclrhd@hotmail.com>
Q: Since the above is valid C++, is the following?: virtual void myfn( char ) = 0; virtual void myfn( int, bool ) = 0;
Absolutely. You can overload virtual functions just like non-virtual functions.
But unless they're all going to be overridden in one single class you're better off using the "template method pattern" and dispatching to differently-named functions to avoid problems with name hiding... or just be disciplined about bringing the base names into derived classes everywhere with "using".
Sure, but in the case leading to this query, they are const and non-const versions of begin(), end(), rbegin(), and rend(). The only opportunity for reuse of an underlying, common implementation function, that I see is for the const overloads to call the non-const overload. The question is whether that is wise. Since the derived class would implement the non-const version, there's no telling whether it would try to modify the state of the object, so casting away const-ness in order to call that overload from the const overload could lead to undefined behavior. As I see it, the derived class will have to implement all eight of those functions, so they'll have to be pure virtual in the base class. -- Rob Stewart stewart@sig.com Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;