Override contra-variance workaround needed
问题 I'm having difficulty finding the (what I'm sure is a very common) design pattern to work around the following problem. Consider this piece of code: class AA {}; class BB : public AA {}; class A { public: virtual void foo(AA& aa) = 0; }; class B : A { public: void foo(BB& bb){cout<<"B::foo"<<endl;} }; int main() { B b; BB bb; b.foo(bb); } This code will not compile because the class B does not override the pure virtual function 'foo'. The compiler considers the foo that B declares only as an