On Sun, Feb 12, 2012 at 9:25 AM, Patrick LeBoutillier <patrick.leboutill...@gmail.com> wrote:
> I'm really no C++ expert, but I think the implementation is not viable > the way it is. If you create a > small C++ program that simulates Inline::CPP like this: > > #include <stdio.h> > > /* Your Child/Parent classes here "as is" */ > > int main(int argv, char **argc){ > Child *c = new Child() ; > printf("%d\n", c->do_something()) ; > printf("%d\n", c->do_another()) ; > > void *x = c ; > printf("%d\n", ((Parent1 *)x)->do_something()) ; > printf("%d\n", ((Parent2 *)x)->do_another()) ; > } > > I gives the same error: > 51 > 17 > 51 > 51 > Patrick, Your explanation was excellent. What needs to be happening is that, as Child inherits from Parent1 and Parent2, the pointer should be cast as a Child type, like in this modification of your test: int main(int argv, char **argc){ Child *c = new Child() ; printf("%d\n", c->do_something()) ; printf("%d\n", c->do_another()) ; void *x = c ; printf("%d\n", ((Child *)x)->do_something()) ; printf("%d\n", ((Child *)x)->do_another()) ; } ...or in more idiomatic C++: int main() { using std::cout; using std::endl; Child *c = new Child() ; cout << c->do_something() << endl; cout << c->do_another() << endl; void *x = c ; cout << static_cast< Child* >(x)->do_something() << endl; cout << static_cast< Child* >(x)->do_another() << endl; return 0; } Though I'm not much closer to a solution, at least your message reminded me that we're dealing with void pointers to objects. Maybe I need to start looking at how and where the casting is being accomplished. Dave -- David Oswald daosw...@gmail.com