invalid static cast



  • Hallo,
    ich versuche gerade ein Programm zu kompilieren, dass ich zwar nicht selbst geschreiben habe, aber ein wenig umändern wollte. Nun sagt er mir aber Folgendes:

    maggy:CancerSim praktikant$ make -f makefile2.txt
    g++  -c -O3  `/Users/praktikant/Desktop/wxMac-2.8.10/build-ansi/wx-config --cxxflags`  -c -o wxGLCanvas2.o wxGLCanvas2.cc
    wxGLCanvas2.cc:25: error: invalid static_cast from type ‘void (wxGLCanvas2::*)()’ to type ‘void (wxEvtHandler::*)(wxEraseEvent&)’
    make: *** [wxGLCanvas2.o] Error 1
    

    Da ich ziemlich neu mit c++ bin, bin ich leider überfragt mit dieser Fehlermeldung. Bisherige Lösungen aus dem Internet haben bei mir leider nicht funktioniert, aber ich hab auch noch nicht so viele durch...

    Hier auf jeden Fall mal die Codes:
    wxGLCanvas2.cc

    #include "wxGLCanvas2.h"
    
    BEGIN_EVENT_TABLE(wxGLCanvas2, wxGLCanvas)
      EVT_PAINT(wxGLCanvas2::OnPaint)
      EVT_ERASE_BACKGROUND(wxGLCanvas2::OnEraseBackground)  //<-- hier ist Zeile 25
    END_EVENT_TABLE()
    
    wxGLCanvas2::wxGLCanvas2(wxWindow * parent, wxGLCanvas2_Render * render)
      : wxGLCanvas(parent,-1), m_render(render)
    {
    
    }
    
    void wxGLCanvas2::OnPaint(wxPaintEvent & e)
    {
      wxPaintDC dc(this);
    //  cout << "wxGLCanvas2::OnPaint" << endl;
      SetCurrent();
      m_render->render();
      SwapBuffers();
    }
    

    wxGLCanvas2.h

    #include "wx/wx.h"
    #include "wx/glcanvas.h"
    
    class wxGLCanvas2_Render
    {
    public:
      virtual void render() = 0;
    };
    
    class wxGLCanvas2 : public wxGLCanvas
    {
      DECLARE_EVENT_TABLE()
    
    public:
    
      wxGLCanvas2(wxWindow * parent, wxGLCanvas2_Render*);
    
      void OnEraseBackground() { };
      void OnPaint(wxPaintEvent&);
    
    protected:
      wxGLCanvas2_Render * m_render;
    };
    

    und der Teil von event.h, wo wxEvtHandler drin ist (event.h wird über wx/wx.h includiert)

    // ----------------------------------------------------------------------------
    // wxEvtHandler: the base class for all objects handling wxWidgets events
    // ----------------------------------------------------------------------------
    
    class WXDLLIMPEXP_BASE wxEvtHandler : public wxObject
    {
    public:
        wxEvtHandler();
        virtual ~wxEvtHandler();
    
        wxEvtHandler *GetNextHandler() const { return m_nextHandler; }
        wxEvtHandler *GetPreviousHandler() const { return m_previousHandler; }
        void SetNextHandler(wxEvtHandler *handler) { m_nextHandler = handler; }
        void SetPreviousHandler(wxEvtHandler *handler) { m_previousHandler = handler; }
    
        void SetEvtHandlerEnabled(bool enabled) { m_enabled = enabled; }
        bool GetEvtHandlerEnabled() const { return m_enabled; }
    
        // process an event right now
        virtual bool ProcessEvent(wxEvent& event);
    
        // add an event to be processed later
        void AddPendingEvent(wxEvent& event);
    
        void ProcessPendingEvents();
    
    #if wxUSE_THREADS
        bool ProcessThreadEvent(wxEvent& event);
    #endif
    
        // Dynamic association of a member function handler with the event handler,
        // winid and event type
        void Connect(int winid,
                     int lastId,
                     int eventType,
                     wxObjectEventFunction func,
                     wxObject *userData = (wxObject *) NULL,
                     wxEvtHandler *eventSink = (wxEvtHandler *) NULL);
    
        // Convenience function: take just one id
        void Connect(int winid,
                     int eventType,
                     wxObjectEventFunction func,
                     wxObject *userData = (wxObject *) NULL,
                     wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
            { Connect(winid, wxID_ANY, eventType, func, userData, eventSink); }
    
        // Even more convenient: without id (same as using id of wxID_ANY)
        void Connect(int eventType,
                     wxObjectEventFunction func,
                     wxObject *userData = (wxObject *) NULL,
                     wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
            { Connect(wxID_ANY, wxID_ANY, eventType, func, userData, eventSink); }
    
        bool Disconnect(int winid,
                        int lastId,
                        wxEventType eventType,
                        wxObjectEventFunction func = NULL,
                        wxObject *userData = (wxObject *) NULL,
                        wxEvtHandler *eventSink = (wxEvtHandler *) NULL);
    
        bool Disconnect(int winid = wxID_ANY,
                        wxEventType eventType = wxEVT_NULL,
                        wxObjectEventFunction func = NULL,
                        wxObject *userData = (wxObject *) NULL,
                        wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
            { return Disconnect(winid, wxID_ANY, eventType, func, userData, eventSink); }
    
        bool Disconnect(wxEventType eventType,
                        wxObjectEventFunction func,
                        wxObject *userData = (wxObject *) NULL,
                        wxEvtHandler *eventSink = (wxEvtHandler *) NULL)
            { return Disconnect(wxID_ANY, eventType, func, userData, eventSink); }
    
        wxList* GetDynamicEventTable() const { return m_dynamicEvents ; }
    
        // User data can be associated with each wxEvtHandler
        void SetClientObject( wxClientData *data ) { DoSetClientObject(data); }
        wxClientData *GetClientObject() const { return DoGetClientObject(); }
    
        void SetClientData( void *data ) { DoSetClientData(data); }
        void *GetClientData() const { return DoGetClientData(); }
    
        // check if the given event table entry matches this event and call the
        // handler if it does
        //
        // return true if the event was processed, false otherwise (no match or the
        // handler decided to skip the event)
        static bool ProcessEventIfMatches(const wxEventTableEntryBase& tableEntry,
                                          wxEvtHandler *handler,
                                          wxEvent& event);
    
        // implementation from now on
        virtual bool SearchEventTable(wxEventTable& table, wxEvent& event);
        bool SearchDynamicEventTable( wxEvent& event );
    
    #if wxUSE_THREADS
        void ClearEventLocker();
    #endif // wxUSE_THREADS
    
        // Avoid problems at exit by cleaning up static hash table gracefully
        void ClearEventHashTable() { GetEventHashTable().Clear(); }
    
    private:
        static const wxEventTableEntry sm_eventTableEntries[];
    
    protected:
        // hooks for wxWindow used by ProcessEvent()
        // -----------------------------------------
    
        // This one is called before trying our own event table to allow plugging
        // in the validators.
        //
        // NB: This method is intentionally *not* inside wxUSE_VALIDATORS!
        //     It is part of wxBase which doesn't use validators and the code
        //     is compiled out when building wxBase w/o GUI classes, which affects
        //     binary compatibility and wxBase library can't be used by GUI
        //     ports.
        virtual bool TryValidator(wxEvent& WXUNUSED(event)) { return false; }
    
        // this one is called after failing to find the event handle in our own
        // table to give a chance to the other windows to process it
        //
        // base class implementation passes the event to wxTheApp
        virtual bool TryParent(wxEvent& event);
    
        static const wxEventTable sm_eventTable;
        virtual const wxEventTable *GetEventTable() const;
    
        static wxEventHashTable   sm_eventHashTable;
        virtual wxEventHashTable& GetEventHashTable() const;
    
        wxEvtHandler*       m_nextHandler;
        wxEvtHandler*       m_previousHandler;
        wxList*             m_dynamicEvents;
        wxList*             m_pendingEvents;
    
    #if wxUSE_THREADS
    #if defined (__VISAGECPP__)
        const wxCriticalSection& Lock() const { return m_eventsLocker; }
        wxCriticalSection& Lock() { return m_eventsLocker; }
    
        wxCriticalSection   m_eventsLocker;
    #  else
        const wxCriticalSection& Lock() const { return *m_eventsLocker; }
        wxCriticalSection& Lock() { return *m_eventsLocker; }
    
        wxCriticalSection*  m_eventsLocker;
    #  endif
    #endif
    
        // Is event handler enabled?
        bool                m_enabled;
    
        // The user data: either an object which will be deleted by the container
        // when it's deleted or some raw pointer which we do nothing with - only
        // one type of data can be used with the given window (i.e. you cannot set
        // the void data and then associate the container with wxClientData or vice
        // versa)
        union
        {
            wxClientData *m_clientObject;
            void         *m_clientData;
        };
    
        // what kind of data do we have?
        wxClientDataType m_clientDataType;
    
        // client data accessors
        virtual void DoSetClientObject( wxClientData *data );
        virtual wxClientData *DoGetClientObject() const;
    
        virtual void DoSetClientData( void *data );
        virtual void *DoGetClientData() const;
    
    private:
        DECLARE_DYNAMIC_CLASS_NO_COPY(wxEvtHandler)
    };
    

    Wenn ihr noch was braucht, sagt Bescheid, ich werd auch weiterhin im Internet stöbern, aber wär toll, wenn jemand mir helfen könnte.

    Danke


  • Mod

    Zumindest die Argumenttypen sollten übereinstimmen:

    class wxGLCanvas2 : public wxGLCanvas
    {
      DECLARE_EVENT_TABLE()
    
    public:
    
      wxGLCanvas2(wxWindow * parent, wxGLCanvas2_Render*);
    
      [b]void OnEraseBackground(wxPaintEvent&) { }[/b]
      void OnPaint(wxPaintEvent&);
    
    protected:
      wxGLCanvas2_Render * m_render;
    };
    


  • oh, ist mir gar nicht aufgefallen, hab ich geändert, ist aber immernoch der selbe Fehler...



  • camper schrieb:

    Zumindest die Argumenttypen sollten übereinstimmen:

    [b]void OnEraseBackground(wxPaintEvent&)[/b]
    

    void OnEraseBackground(wxEraseEvent&)



  • Super, hat alles geklappt, waren ja auch doofe Fehler 🙄
    Danke nochmal


Anmelden zum Antworten