2010-10-17 54 views
0

好吧,我遇到了一個非常奇怪的問題。WxWidgets:Troubling Callling wxFrame構造器E

我有一個具有兩個框架,一主一,和次級一個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()'|的調用沒有匹配的函數

這是調用父類的構造函數的錯誤,但我只是複製它的原始幀,這工作得很好做的方式。

什麼是?

EDIT 1:

好的,我取代

NUEAsset(wxFrame *frame){} 

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

,現在發生故障在連接階段,錯誤如下:

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

我不能讓h這個錯誤的頭部或尾部。

編輯2:

哦,我不斷收到這樣的警告一樣好,但我一直在忽視它。這可能是相關的:

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

編輯3:我想我解決了問題,使用下面的信息和一些挖掘。

事實證明,我被定義爲不再有那些事件框架的一些事件。

改變了defs,它現在似乎工作。

回答

1

AssetEd沒有一個默認的構造函數。如果你定義了你自己的構造函數,默認的構造函數將不會被隱含地提供。

的問題是,需要以某種方式構造的派生類的基本對象。如果你沒有從初始化列表調用合適的構造函數,默認的構造函數將被隱式使用。

NUEAsset必須簡單地調用用合適的參數的基類的構造函數,如

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

好了,現在它得到一個非常奇怪的錯誤:)] + 0x7e格式)||未定義的參考'虛表的NUEAsset」 | – Biosci3c 2010-10-17 18:05:28

+0

有時會這樣做,我不知道爲什麼。它甚至沒有確定問題所在的頭文件中的位置。另外,即使是狡猾的,事實是這和其他框架一樣(沒有調用默認構造函數,並且工作正常)。 – Biosci3c 2010-10-17 18:05:53