开发者

#including a class header does not specify type

I am encountering a very strange problem in my wxWidgets application. What I am trying to do is use a custom wxPanel resource to allow for some redundancy control and providing methods that allow me to work easier. This problem was not occurring before I tried to pass access to a resource in the main frame to each panel.

What I am doing is using #include to include the class header of the wxPanel resource in the header of the main class. However, when trying to declare a resource of the type CopyRow, which is in the header file I am including, I get the error CopyRow does not name a type

Here is the code for the main class header,

#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>
#inclu开发者_开发百科de <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

And here is the code for 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

Can anyone explain this error to me? I have no clue right now.


You are can't include CPAMountMain.h in CopyRow.h and CopyRow.h in CPAMountMain.h! You have to decide the order in wich you want to include the files.

Since CPAMountMain.h only use pointers to CopyRow class, you can use a forward declaration instead of including CopyRow.h:

// CPAMountMain.h
class CopyRow;

and remove the #include "CopyRow.h" in CPAMountMain.h, this should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜