From: William S F. <ws...@fu...> - 2009-05-26 21:56:10
|
Josh Cherry wrote: > > On Tue, 26 May 2009, Philipp Kraft wrote: > >> Maybe I wasn't precise enough. It is not the problem to access A from B with >> some function (get_A is a member of B) but to use b as an A in a "quasi duck >> typing way". >> This works: >>>>> ct.print_a(b.get_A()) # but it's ugly and hard to explain to Non-C++ >> Python programmers >> >> This should work: >>>>> ct.print_a(b) # Simple to use, but how to do it with SWIG? >> The idea is to have a "HAS A" relationship, and, in some cases an "IS A" >> relationship-like behaviour without using inheritance. > > You could provide typemaps for A& that accept B. Alternatively, if the > number of functions is small you could provide overloads that take a B& > for wrapping purposes. > Also take a look at %implicitconv documented in the CHANGES file. If that doesn't work, can you add conversion operators dealing with pointers as well as references in your code? If so you should be able to use %types. Let me know and I'll try put together an example. William |