#include #include "prelude.h" #include "ref_count.h" using std::cout; using std::endl; // A <-- B X <-- Y struct A { virtual void f() const =0; }; struct B : public A { void f() const { cout << "B::f()" << endl; } }; struct X { virtual void g() const =0; }; struct Y : public X { void g() const { cout << "Y::g()" << endl; } }; struct fun_from_A_to_Y : public CFunType,Ref > { Ref operator()( Ref ) const { return Ref(new Y); } }; int main() { Fun1,Ref > fay = makeFun1( fun_from_A_to_Y() ); Fun1,Ref > fbx = fay; // woohoo! fbx( Ref(new B) )->g(); Ref rb; Ref rcb = rb; Ref rv = rb; // unsafe if( rcb == rb ) cout << "yay" << endl; //rb = rcb; //Fun1 oops = fbx; //Fun1 oops = explicit_convert1(fbx); // Fun1 crap = fbx; return 0; }