Move-Konstruktor aufrufen base-class-Move-Konstruktor

Ich habe eine base-Klasse, die im wesentlichen umschließt, die Sie hinzufügen einer Klasse zu einer beliebigen windows-handle (e.g, HWND, HFONT), und verwendet eine policy-Klasse zu attach/detach und zerstören:

//class SmartHandle
template<typename THANDLE, class TWRAPPER, class TPOLICY>
class SmartHandle : boost::noncopyable
{
private:
    TPOLICY*  m_pPolicy;    //Policy
    bool m_bIsTemporary;    //Is this a temporary window?

    SmartHandle();  //no default ctor
    SmartHandle(const SmartHandle<THANDLE, TWRAPPER, TPOLICY>&);    //no cctor
protected:
    THANDLE   m_hHandle;    //Handle to the underlying window

    TPOLICY& policy() {return(*m_pPolicy);};

    //ctor that attaches but is temporary
    SmartHandle(const THANDLE& _handle, bool _temporary) : m_hHandle(_handle)
                                                         , m_bIsTemporary(_temporary)
    {
        m_pPolicy = new TPOLICY(reinterpret_cast<TWRAPPER&>(*this));
        if(_handle)
            m_pPolicy->attach(_handle);
    };  //eo ctor

    //move ctor
    SmartHandle(SmartHandle<THANDLE, TWRAPPER, TPOLICY>&& _rhs) : m_hHandle(_rhs.m_hHandle)
                                                                      , m_bIsTemporary(_rhs.m_bIsTemporary)
    {
        m_pPolicy = new TPOLICY(reinterpret_cast<TWRAPPER&>(*this));
        m_pPolicy->attach(m_hHandle);
        const_cast<SmartHandle&>(_rhs).m_hHandle = NULL;
    };  //eo mtor

    //dtor
    virtual ~SmartHandle()
    {
        if(m_hHandle)
        {
            m_pPolicy->detach(m_hHandle);
            if(!m_bIsTemporary)
                m_pPolicy->destroy(m_hHandle);
            m_hHandle = NULL;
        };
        delete(m_pPolicy);
        m_pPolicy = NULL;
    }; //eo dtor

Beachten Sie, dass ich erklärte der copy-Konstruktor private (ohne Implementierung), weil ich nicht will das die Klasse kopiert werden, aber einen Umzug ist erlaubt.

Meine Window - Klasse wird von dieser:

    class GALLOW_API Window : SmartHandle<HWND, Window, detail::_hWndPolicy>
    {
    friend class Application;
    private:
        static LRESULT CALLBACK wndProc(HWND _hWnd, UINT _message, WPARAM _wParam, LPARAM _lParam);

        //no copy/default ctor
        Window();
        Window(const Window&);
    protected:

    public:
        static const String ClassName;
        Window(const HWND& _hWnd);
        Window(const WindowCreateInfo& _createInfo);
        Window(Window&& _rhs);
        virtual ~Window();
    };  //eo class Window

Wieder einmal, kopieren Sie default/copy-ctors. Die Umsetzung der move-Konstruktor ist:

    Window::Window(Window&& _rhs) : SmartHandle(_rhs)
    {
    };  //eo mtor

Jedoch während der Kompilierung bekomme ich folgende Fehlermeldung in der ersten Zeile des move-Konstruktor Umsetzung:

1>c:\\documents\visual studio 2010\projects\gallow\gallow\window.cpp(81): error C2248: 'gallow::SmartHandle<THANDLE,TWRAPPER,TPOLICY>::SmartHandle' : cannot access private member declared in class 'gallow::SmartHandle<THANDLE,TWRAPPER,TPOLICY>'

So, es scheint, als ob es versucht, zu rufen den copy-Konstruktor (das habe ich deklariert, dass private) anstatt den move-Konstruktor. Ist es etwas einfacher, ich bin hier noch fehlt?

Vielen Dank im Voraus.

EDIT: Geändert mtor-so war es nicht-Konstante, der Fehler bleibt.
EDIT2: ich benutze Visual C++ 2010.

InformationsquelleAutor Moo-Juice | 2010-12-08
Schreibe einen Kommentar