6.3w+
社区成员
编程小白,请大佬们帮忙看看,从wxformbuilder中导入的代码,写动态事件的时候就提示redefinition的错误,代码如下:
h文件
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#pragma once
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/button.h>
#include <wx/string.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <wx/icon.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 <wx/panel.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class MyFrame1
///////////////////////////////////////////////////////////////////////////////
class MyFrame1 : public wxFrame
{
private:
protected:
wxButton* m_button31;
// Virtual event handlers, override them in your derived class
virtual void OnOK( wxCommandEvent& event ) { event.Skip(); }
public:
MyFrame1( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 1280,720 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
~MyFrame1();
};
///////////////////////////////////////////////////////////////////////////////
/// Class MyPanel4
///////////////////////////////////////////////////////////////////////////////
class MyPanel4 : public wxPanel
{
private:
protected:
public:
MyPanel4( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
~MyPanel4();
};
cpp文件
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.1-0-g8feb16b3)
// http://www.wxformbuilder.org/
//
// PLEASE DO *NOT* EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "NCPP.h"
///////////////////////////////////////////////////////////////////////////
MyFrame1::MyFrame1( 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* bSizer2;
bSizer2 = new wxBoxSizer( wxVERTICAL );
m_button31 = new wxButton( this, wxID_ANY, wxT("MyButton"), wxDefaultPosition, wxDefaultSize, 0 );
bSizer2->Add( m_button31, 0, wxALL, 5 );
this->SetSizer( bSizer2 );
this->Layout();
this->Centre( wxBOTH );
// Connect Events
m_button31->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame1::OnOK ), NULL, this );
}
MyFrame1::~MyFrame1()
{
// Disconnect Events
m_button31->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( MyFrame1::OnOK ), NULL, this );
}
MyPanel4::MyPanel4( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name )
{
}
MyPanel4::~MyPanel4()
{
}
void MyFrame1::OnOK(wxCommandEvent& event)
{
Close();
}
错误提示
error: redefinition of 'void MyFrame1::OnOK(wxCommandEvent&)'
出错信息说的是“MyFrame1::OnOK(wxCommandEvent&)'” 这个成员函数 定义了两遍。你在代码(包括wxFormBuilder 自动生成的)中找找。或者,也有可能:你是不是把某个 .cpp 文件,给 #include 了???
支持,推荐图形界面编程:https://blog.csdn.net/u010165006/article/details/122217326 多图、实例、书籍
————————————————————