/trunk/Examples/test-suite/director_alternating.i

# · Swig · 36 lines · 30 code · 6 blank · 0 comment · 0 complexity · 506d269c0ee2a1b77d517398d80c8a19 MD5 · raw file

  1. // Checks if calls to a method being defined in the base class, not
  2. // overridden in the subclass, but again overridden in a class derived from
  3. // the first subclass are dispatched correctly.
  4. %module(directors="1") director_alternating;
  5. %feature("director") Foo;
  6. %inline %{
  7. struct Foo {
  8. virtual ~Foo() {}
  9. virtual int id() {
  10. return 0;
  11. }
  12. };
  13. struct Bar : Foo {};
  14. struct Baz : Bar {
  15. virtual int id() {
  16. return 2;
  17. }
  18. };
  19. // Note that even though the return value is of type Bar*, it really points to
  20. // an instance of Baz (in which id() has been overridden).
  21. Bar *getBar() {
  22. static Baz baz;
  23. return &baz;
  24. }
  25. // idFromGetBar() obviously is equivalent to getBar()->id() in C++ – this
  26. // should be true from the target language as well.
  27. int idFromGetBar() {
  28. return getBar()->id();
  29. }
  30. %}