【问题标题】:WxWidgets: Troubling Callling wxFrame ConstructorEWxWidgets:麻烦调用 wx 框架构造函数
【发布时间】:2010-10-17 17:57:21
【问题描述】:

好的,我遇到了一个非常奇怪的问题。

我有一个 wxWidgets 程序,它有两个框架,一个主框架和一个辅助框架。

主要的有一个按钮,调用第二个打开。

我无法从第二个 wxframe 的类调用派生类,因此我将类的声明/实现移到了主框架的类之前。

现在我得到一个编译错误。

这是包含派生的 wxFrame 类的头文件:

/***************************************************************
 * Name:      NUEMain.h
 * Purpose:   Defines Application Frame
 * Author:    Cypher ()
 * Created:   2010-10-02
 * Copyright: Cypher ()
 * License:
 **************************************************************/
#include "System.h"
#ifndef NUEMAIN_H
#define NUEMAIN_H


#include "NUEApp.h"
#include "GUIFrame.h"
#include "System.h"
#include <wx/wx.h>


class NUEAsset : public AssetEd
{
    public:
        NUEAsset(wxFrame *frame){} <-- Error here
        ~NUEAsset(){};

        //Xml object
        XmlO SysX;
    private:
        virtual void OnClose(wxCloseEvent& event);
        virtual void OnQuit(wxCommandEvent& event);
        virtual void OnAbout(wxCommandEvent& event);

        //Open File Event
        virtual void OpenFile( wxCommandEvent& event ){
            wxFileDialog* OpenDialog = new wxFileDialog(
            this, _("Choose a file to open"), wxEmptyString, wxEmptyString,_("XML Files (*.xml)|*.xml"),wxFD_OPEN, wxDefaultPosition);

            // Creates a "open file" dialog with 4 file types
            if (OpenDialog->ShowModal() == wxID_OK) // if the user click "Open" instead of "Cancel"
            {
                //Change Statusbar to display path of opened file
                SetStatusText(OpenDialog->GetPath(),0);

                //Set m_SysListBox contents to names from ssys.xml
                SysX.load(OpenDialog->GetPath());
                Asset assetsys;
                //Start adding names to m_SysListbox
                //Pointer to system
                for(int i = 0; i < SysX.Sys.size(); i++){
                    assetsys = SysX.Sys.at(i);
                    //Get name of system as string
                    //Convert name from string to wxString
                    m_SysListBox->AppendString(assetsys.name);
                }
                // MainEditBox->LoadFile(CurrentDocPath); //Opens that file
            }
                //SetTitle(wxString("Edit - ") <<OpenDialog->GetFilename()); // Set the Title to reflect the file open


        // Clean up after ourselves
        OpenDialog->Destroy();


        }
        //Handle clicking on a system
        virtual void sys_click( wxCommandEvent& event ) {
            //Get the index of the selected item
            int ind;
            ind = m_SysListBox->GetSelection();

            wxString tmp_sys_nam;
            wxString tmp_x;
            wxString tmp_y;

            tmp_sys_nam = SysX.Sys.at(ind).name;
            tmp_x << SysX.Sys.at(ind).x_pos;
            tmp_y << SysX.Sys.at(ind).y_pos;

            //Set the asset name listbox
            m_textPNAME->ChangeValue(tmp_sys_nam);

            //Set the X_pos listbox
            m_textRadius->ChangeValue(tmp_x);

            //Set the Y_pos listbox
            m_textStars->ChangeValue(tmp_y);

        }
};


class NUEFrame: public GUIFrame
{
    public:
        NUEFrame(wxFrame *frame);
        ~NUEFrame();

        //Xml object
        XmlO SysX;
    private:
        virtual void OnClose(wxCloseEvent& event);
        virtual void OnQuit(wxCommandEvent& event);
        virtual void OnAbout(wxCommandEvent& event);

        //Launch Asset Editor
        virtual void launch_asset_ed( wxCommandEvent& event ) {
            NUEAsset* asset_ed_frame = new NUEAsset(0L);
            asset_ed_frame->SetIcon(wxICON(aaaa)); // To Set App Icon
            asset_ed_frame->Show();

        }

        //Open File Event
    /*    virtual void OpenFile( wxCommandEvent& event ){
            wxFileDialog* OpenDialog = new wxFileDialog(
            this, _("Choose a file to open"), wxEmptyString, wxEmptyString,_("XML Files (*.xml)|*.xml"),wxFD_OPEN, wxDefaultPosition);

            // Creates a "open file" dialog with 4 file types
            if (OpenDialog->ShowModal() == wxID_OK) // if the user click "Open" instead of "Cancel"
            {
                //Change Statusbar to display path of opened file
                SetStatusText(OpenDialog->GetPath(),0);

                //Set m_SysListBox contents to names from ssys.xml
                SysX.load(OpenDialog->GetPath());
                Asset assetsys;
                //Start adding names to m_SysListbox
                //Pointer to system
                for(int i = 0; i < SysX.Sys.size(); i++){
                    assetsys = SysX.Sys.at(i);
                    //Get name of system as string
                    //Convert name from string to wxString
                    m_SysListBox->AppendString(assetsys.name);
                }
                // MainEditBox->LoadFile(CurrentDocPath); //Opens that file
            }
                //SetTitle(wxString("Edit - ") <<OpenDialog->GetFilename()); // Set the Title to reflect the file open


        // Clean up after ourselves
        OpenDialog->Destroy();


        } */
        //Handle clicking on a system
     /*   virtual void sys_click( wxCommandEvent& event ) {
            //Get the index of the selected item
            int ind;
            ind = m_SysListBox->GetSelection();

            wxString tmp_sys_nam;
            wxString tmp_x;
            wxString tmp_y;

            tmp_sys_nam = SysX.Sys.at(ind).name;
            tmp_x << SysX.Sys.at(ind).x_pos;
            tmp_y << SysX.Sys.at(ind).y_pos;

            //Set the asset name listbox
            m_textPNAME->ChangeValue(tmp_sys_nam);

            //Set the X_pos listbox
            m_textRadius->ChangeValue(tmp_x);

            //Set the Y_pos listbox
            m_textStars->ChangeValue(tmp_y);

        }*/
};

#endif // NUEMAIN_H

这是类派生的标题:

///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Sep  8 2010)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////

#ifndef __GUIFrame__
#define __GUIFrame__

#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/bitmap.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/menu.h>
#include <wx/frame.h>
#include <wx/stattext.h>
#include <wx/listbox.h>
#include <wx/textctrl.h>
#include <wx/toolbar.h>
#include <wx/statusbr.h>

///////////////////////////////////////////////////////////////////////////

#define idMenuQuit 1000
#define idMenuAbout 1001

///////////////////////////////////////////////////////////////////////////////
/// Class GUIFrame
///////////////////////////////////////////////////////////////////////////////
class GUIFrame : public wxFrame 
{
 private:

 protected:

  wxButton* m_buttonAsset;
  wxButton* m_buttonShip;


  wxButton* m_buttonTech;
  wxButton* m_buttonOutfit;

  wxMenuBar* m_menubar2;
  wxMenu* m_file;

  // Virtual event handlers, overide them in your derived class
  virtual void OnClose( wxCloseEvent& event ) { event.Skip(); }
  virtual void launch_asset_ed( wxCommandEvent& event ) { event.Skip(); }


 public:

  GUIFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("NUE v0.0.1a"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
  ~GUIFrame();

};

///////////////////////////////////////////////////////////////////////////////
/// Class AssetEd
///////////////////////////////////////////////////////////////////////////////
class AssetEd : public wxFrame 
{
 private:

 protected:
  wxMenuBar* mbar;
  wxMenu* fileMenu;
  wxMenu* helpMenu;
  wxStaticText* m_staticTextSysboxlabel;
  wxListBox* m_SysListBox;
  wxStaticText* m_staticParamslabel;
  wxStaticText* m_staticText4;
  wxTextCtrl* m_textPNAME;
  wxStaticText* m_staticText5;
  wxTextCtrl* m_textRadius;
  wxStaticText* m_staticText6;
  wxTextCtrl* m_textStars;
  wxStaticText* m_staticText61;
  wxTextCtrl* m_textInterference;
  wxStaticText* m_staticText611;
  wxStaticText* m_staticText612;
  wxTextCtrl* m_textPosX;
  wxStaticText* m_staticText6121;
  wxTextCtrl* m_textPosY;
  wxStaticText* m_staticLinksLabel;
  wxListBox* m_SysHyperlinkslist;
  wxToolBar* m_toolBar1;
  wxStatusBar* statusBar;

  // Virtual event handlers, overide them in your derived class
  virtual void OpenFILE( wxCommandEvent& event ) { event.Skip(); }
  virtual void OnQuit( wxCommandEvent& event ) { event.Skip(); }
  virtual void OnAbout( wxCommandEvent& event ) { event.Skip(); }
  virtual void sys_click( wxCommandEvent& event ) { event.Skip(); }


 public:

  AssetEd( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 915,500 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
  ~AssetEd();

};

#endif //__GUIFrame__

这是我得到的错误: \ NUEMain.h|23|错误:没有匹配函数调用 'AssetEd::AssetEd()'|

这是在父类中调用构造函数的错误,但我只是复制了对原始框架的处理方式,效果很好。

怎么了?

编辑 1:

好的,我换了

NUEAsset(wxFrame *frame){} 

NUEAsset(wxFrame *frame): AssetEd(frame){}

它现在在链接阶段失败并出现以下错误:

)]+0x7e)||undefined reference to `vtable for NUEAsset'|

我无法确定这个错误的正面或反面。

编辑 2:

哦,我也不断收到此警告,但我一直忽略它。这可能是相关的:

||warning: auto-importing has been activated without --enable-auto-import specified on the command line.|

编辑 3:我想我使用下面的信息和一些挖掘解决了这个问题。

事实证明,我正在为不再具有这些事件的框架定义一些事件。

更改了定义,现在似乎可以工作了。

【问题讨论】:

    标签: c++ constructor wxwidgets linker-errors


    【解决方案1】:

    AssetEd 没有默认构造函数。如果你定义了自己的任何构造函数,默认的构造函数将不会被隐式提供。

    问题是派生类的基对象需要以某种方式构造。如果你没有从初始化列表中调用合适的构造函数,默认的构造函数将被隐式使用。

    NUEAsset 必须简单地使用合适的参数调用基类的构造函数,例如

    NUEAsset(wxFrame *frame): Asset(frame) {}
    

    【讨论】:

    • 好的,现在出现了一个非常奇怪的错误:)]+0x7e)||undefined reference to `vtable for NUEAsset'|
    • 它有时会这样,我不知道为什么。它甚至没有确定头文件中问题所在的位置。此外,更奇怪的是,这与其他框架的处理方式相同(无需调用默认构造函数,并且工作正常)。
    猜你喜欢
    • 1970-01-01
    • 2011-04-15
    • 1970-01-01
    • 1970-01-01
    • 2011-12-23
    • 1970-01-01
    • 1970-01-01
    • 2017-05-02
    • 2017-11-20
    相关资源
    最近更新 更多