[C++-sig] operator ->, cast operator

Leonard "paniq" Ritter paniq at paniq.org
Sat Mar 12 23:02:19 CET 2005


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?




More information about the Cplusplus-sig mailing list