[C++-sig] Re: operator ->, cast operator
David Abrahams
dave at boost-consulting.com
Sat Mar 12 23:46:30 CET 2005
"Leonard \"paniq\" Ritter" <paniq at paniq.org> writes:
> i see there are easy methods of exporting operators that deal with
> values and mathematical operations, but is there any chance of exporting
> pointer-to operators?
>
> in this particular case i am exporting a custom interface pointer class
> to python.
>
> in c++ i can use such a smart pointer like this:
>
> Ptr<View> view(L"µ.Sandoz.View");
> if (view)
> {
> view->Attach(hWnd, true);
>
> ...
>
> where Ptr<T> exposes its member T _object using
>
> InterfaceType* operator->()
> {
> return _object;
> }
>
> i'm exposing Ptr<View> as "View" and the View interface as
> "ViewInterface" to python.
>
> what i'd like to write in python would be something along the lines of
>
> view = View("µ.Sandoz.View")
> view.Attach(self.window, true)
>
> can i realize this without much trouble?
Yeah, just export View using Ptr<View> as the HeldType.
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list