2011-09-04 48 views
0

我在我的wxWidgets應用程序中遇到了一個非常奇怪的問題。我試圖做的是使用自定義的wxPanel資源來允許一些冗餘控制,並提供讓我工作更輕鬆的方法。在我嘗試將訪問主框架中的資源傳遞給每個面板之前,沒有發生此問題。#包含類頭文件不指定類型

我正在做的是使用#include將wxPanel資源的類標題包含在主類的標頭中。然而,試圖申報類型CopyRow的資源,這是在頭文件,我包括什麼時候,我得到的錯誤CopyRow does not name a type

下面是主要的類頭的代碼,

#ifndef CPAMOUNTMAIN_H 
#define CPAMOUNTMAIN_H 

//(*Headers(CPAmountFrame) 
#include <wx/sizer.h> 
#include <wx/stattext.h> 
#include <wx/menu.h> 
#include <wx/spinctrl.h> 
#include <wx/statline.h> 
#include "CopyRow.h" 
#include <wx/panel.h> 
#include <wx/frame.h> 
#include <wx/statusbr.h> 
//*) 

class CPAmountFrame: public wxFrame 
{ 
    public: 

     CPAmountFrame(wxWindow* parent,wxWindowID id = -1); 
     void UpdateTotal(); 
     virtual ~CPAmountFrame(); 

    private: 

     //(*Handlers(CPAmountFrame) 
     void OnQuit(wxCommandEvent& event); 
     void OnAbout(wxCommandEvent& event); 
     void OntotalCopiesChange(wxSpinEvent& event); 
     static void CallTotalCopies(); 
     //*) 

     //(*Identifiers(CPAmountFrame) 
     static const long ID_CUSTOM1; 
     static const long ID_CUSTOM2; 
     static const long ID_CUSTOM3; 
     static const long ID_CUSTOM4; 
     static const long ID_CUSTOM5; 
     static const long ID_CUSTOM6; 
     static const long ID_STATICLINE1; 
     static const long ID_STATICTEXT1; 
     static const long ID_SPINCTRL1; 
     static const long ID_STATICTEXT2; 
     static const long ID_PANEL1; 
     static const long idMenuQuit; 
     static const long idMenuAbout; 
     static const long ID_STATUSBAR1; 
     //*) 

     //(*Declarations(CPAmountFrame) 
     CopyRow* Custom4; 
     wxStaticText* totalPrice; 
     CopyRow* Custom1; 
     CopyRow* Custom5; 
     CopyRow* Custom2; 
     CopyRow* Custom3; 
     wxPanel* Panel1; 
     wxStaticText* StaticText1; 
     wxStatusBar* StatusBar1; 
     wxStaticLine* StaticLine1; 
     CopyRow* Custom6; 
     wxSpinCtrl* totalCopies; 
     //*) 

     DECLARE_EVENT_TABLE() 
}; 

#endif // CPAMOUNTMAIN_H 

而且這裏是CopyRow.h代碼,

#ifndef COPYROW_H 
#define COPYROW_H 

#ifndef WX_PRECOMP 
    //(*HeadersPCH(CopyRow) 
    #include <wx/sizer.h> 
    #include <wx/stattext.h> 
    #include <wx/panel.h> 
    //*) 
#endif 
//(*Headers(CopyRow) 
#include <wx/spinctrl.h> 
//*) 
#include "CPAmountMain.h" 

class CopyRow: public wxPanel 
{ 
    public: 

     CopyRow(wxWindow* parent,const char* label,wxSpinCtrl* copies,wxWindowID id=wxID_ANY,const wxPoint& pos=wxDefaultPosition,const wxSize& size=wxDefaultSize); 
     void SetLabel(const char* label); 
     void SetPrice(double price); 
     void SetCounter(int value); 
     int GetCounter(); 
     virtual ~CopyRow(); 

    private: 

     //(*Declarations(CopyRow) 
     wxStaticText* copyLabel; 
     wxSpinCtrl* numCopies; 
     wxStaticText* copyPrice; 
     //*) 

     //(*Identifiers(CopyRow) 
     static const long ID_SPINCTRL1; 
     static const long ID_STATICTEXT1; 
     static const long ID_STATICTEXT2; 
     //*) 

     wxSpinCtrl* totalCopies; 

     //(*Handlers(CopyRow) 
     void OnnumCopiesChange(wxSpinEvent& event); 
     //*) 
     DECLARE_EVENT_TABLE() 
}; 

#endif 

任何人都可以解釋這個錯誤給我嗎?我現在沒有線索。

+2

這是你得到的唯一錯誤嗎?你確定它在'cpamountmain.h'中嗎?它是什麼?您發佈錯誤是件好事,但您需要發佈所有錯誤(如果不是唯一錯誤)以及錯誤的確切文本,而不僅僅是錯誤(即包含文件和行信息)。 –

+0

@Seth它位於主標題中的第60,62,63,64,65和70行。基本上無處不在,聲明類型爲CopyRow的東西。 –

+0

是否還有其他錯誤?仔細地看。 –

回答

3

您無法在CopyRow.h和CPAMountMain.h中的CopyRow.h中包含CPAMountMain.h!你必須決定你想包括文件的順序。

由於CPAMountMain.h只使用指針到CopyRow類,你可以使用預先聲明的,而不是包括CopyRow.h:

// CPAMountMain.h 
class CopyRow; 

和CPAMountMain.h刪除#include "CopyRow.h",這應該工作。

+1

或從CopyRow.h中刪除'include CPAmountMain.h' – Mat

+0

或者確保首先包含'CopyRow.h',但這是一個不好的解決方案。 +1 –

+0

@Mat是的,它實際上好多了! –