Warum ist der Pointer nicht NULL?



  • Jetzt habe ich das soweit verstanden.

    Das const rechts von einer Methode verhindert, das man in dieser Methode keine Membervariablen verändern kann, oder?



  • Ja. Es muss außerdem beachtet werden, dass innerhalb dieser Methode keine Methode aufgerufen werden darf, die nicht const-qualifiziert ist.



  • Gut. Ich habe meinen Code nun soweit angepasst. Ist das so nun korrekt?

    Foo.h

    #ifndef __Foo__
    #define __Foo__
    
    class Foo
    {
    	private:
    		wxString Test;
    
    	public:
    		void SetTest(const wxString& inTest)
    		{
    			Test = inTest;
    		}
    
    	public:
    		const wxString& GetTest() const
    		{
    			return Test;
    		}
    };
    
    #endif
    

    App.cpp

    #ifdef WX_PRECOMP
    #include "wx_pch.h"
    #endif
    
    #ifdef __BORLANDC__
    #pragma hdrstop
    #endif
    
    #include <wx/wx.h>
    
    #include "MainFrame.h"
    
    class App : public wxApp
    {
        public: virtual bool OnInit()
        {
            MainFrame* mfMainFrame = new MainFrame(0L);
            mfMainFrame->SetIcon(wxICON(MainIcon));
            mfMainFrame->Show();
    
            return true;
        }
    };
    
    IMPLEMENT_APP(App);
    

    MainFrame.h

    ///////////////////////////////////////////////////////////////////////////
    // C++ code generated with wxFormBuilder (version Sep  8 2010)
    // http://www.wxformbuilder.org/
    //
    // PLEASE DO "NOT" EDIT THIS FILE!
    ///////////////////////////////////////////////////////////////////////////
    
    #ifndef __MainFrame__
    #define __MainFrame__
    
    #include <wx/string.h>
    #include <wx/button.h>
    #include <wx/gdicmn.h>
    #include <wx/font.h>
    #include <wx/colour.h>
    #include <wx/settings.h>
    #include <wx/sizer.h>
    #include <wx/frame.h>
    
    #include "Foo.h"
    
    ///////////////////////////////////////////////////////////////////////////
    
    ///////////////////////////////////////////////////////////////////////////////
    /// Class MainFrame
    ///////////////////////////////////////////////////////////////////////////////
    class MainFrame : public wxFrame
    {
    	private:
    
    	protected:
    		wxButton* Button1;
    
    		virtual void OnButton1Click(wxCommandEvent& event)
    		{
    			Foo Blau;
    			wxString Eins = "Eins";
    			wxString Zwei = "";
    
    			Blau.SetTest(Eins);
    			Zwei = Blau.GetTest();
    
    			Button1->SetLabel(Zwei);
    		}
    
    	public:
    
    		MainFrame(wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(500,300), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL);
    		~MainFrame();
    
    };
    
    #endif //__MainFrame__
    

    MainFrame.cpp

    ///////////////////////////////////////////////////////////////////////////
    // C++ code generated with wxFormBuilder (version Sep  8 2010)
    // http://www.wxformbuilder.org/
    //
    // PLEASE DO "NOT" EDIT THIS FILE!
    ///////////////////////////////////////////////////////////////////////////
    
    #include "MainFrame.h"
    
    ///////////////////////////////////////////////////////////////////////////
    
    MainFrame::MainFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
    {
    	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
    
    	wxBoxSizer* BoxSizer1;
    	BoxSizer1 = new wxBoxSizer( wxVERTICAL );
    
    	Button1 = new wxButton( this, wxID_ANY, wxT("MyButton"), wxDefaultPosition, wxDefaultSize, 0 );
    	BoxSizer1->Add( Button1, 0, wxALL, 5 );
    
    	this->SetSizer( BoxSizer1 );
    	this->Layout();
    
    	this->Centre( wxBOTH );
    
    	// Connect Events
    	Button1->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::OnButton1Click ), NULL, this );
    }
    
    MainFrame::~MainFrame()
    {
    	// Disconnect Events
    	Button1->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MainFrame::OnButton1Click ), NULL, this );
    
    }
    


  • *push*



  • Dein Foo.h sieht, bis auf den reservierten Bezeichner "__Foo__", gut aus.


Anmelden zum Antworten