From: Johann Hibschman Date: 2001-11-30T04:15:08+09:00 Subject: [ruby-talk:26946] Re: Interfacing to a C++ library (was: overload possible?) >>>>> "KS" == Kevin Smith writes: KS> For example, you might have a C++ Widget, and Button which KS> inherits from Widget. Now on the Ruby side, you want a Ruby KS> Widget that inherits from the C++ Widget, and you want a Ruby KS> Button that inherits from the C++ Button, BUT ALSO inherits KS> from the Ruby Button. Hm. I just did this, or think I did. What was the problem? My C++ class structure for a Poisson solver was Problem - Problem2 - Problem3 I created the class objects in Ruby normally... cProblem = rb_define_class_under(mFish, "Problem", rb_cObject); cProblem2 = rb_define_class_under(mFish, "Problem2", cProblem); cProblem3 = rb_define_class_under(mFish, "Problem3", cProblem); Defined all the methods of the Problem class under cProblem rb_define_singleton_method(cProblem, "new", RB_METHOD(problem_new), 0); rb_define_method(cProblem, "smooth", RB_METHOD(problem_smooth), 2); rb_define_method(cProblem, "residual", RB_METHOD(problem_residual), 2); Then just defined the creation methods on cProblem2 and 3: rb_define_singleton_method(cProblem2, "new", RB_METHOD(problem2_new), 2); rb_define_singleton_method(cProblem3, "new", RB_METHOD(problem3_new), 2); So, what's wrong with this? Since C++ can cast the pointers to Problem2 objects to Problem objects, it had no problem with the wrapper functions. --Johann