wxwidgets编程遇到redefinition的错误

Cruelbeast 2023-03-16 16:31:26

编程小白,请大佬们帮忙看看,从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&)'

...全文
169 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
南郁 2023-03-19
  • 打赏
  • 举报
回复

出错信息说的是“MyFrame1::OnOK(wxCommandEvent&)'” 这个成员函数 定义了两遍。你在代码(包括wxFormBuilder 自动生成的)中找找。或者,也有可能:你是不是把某个 .cpp 文件,给 #include 了???

ooolinux 2023-03-16
  • 打赏
  • 举报
回复

支持,推荐图形界面编程:https://blog.csdn.net/u010165006/article/details/122217326 多图、实例、书籍
————————————————————






64,676

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧