2012-11-04 23 views
0

我不太清楚這是否應該被認爲是一個C++的問題或wxWidgets的依賴關係:C++,包括使用的wxWidgets和OpenGL

我正在一個相當簡單的wxWidgets的接口上,將允許用戶繪製三角形。因此,我有一個畫布(OpenGLCanvas類)和一個wxWindow(CMainFrame類),問題是我希望我的畫布有一個窗口的實例,反之亦然。錯誤的來源是當編譯器到達OpenGLCanvas中我的CMainFrame實例所在的時候,它(CMainFrame)還沒有被定義,如果我在這裏改變#include的順序,就會發生同樣的事情。我的代碼:

OpenGLCanvas.cpp:

#include "mainframe.h" 
#include "openglcanvas.h" 

... 

OpenGLCanvas::OpenGLCanvas(wxWindow *parent, wxWindowID id,const wxPoint& pos, const   wxSize& size,long style, const wxString& name): 
        wxGLCanvas(parent, id, pos, size, style, name) 
{ 
frame = (CMainFrame) parent; 
} 

openGLCanvas.h:

#ifndef __OPENGLCANVAS_H__ 
#define __OPENGLCANVAS_H__ 

#include "wx/wx.h" 
#include <wx/glcanvas.h> 


class OpenGLCanvas: public wxGLCanvas { 



public: 
CMainFrame* frame; 
... 
#endif 

mainframe.cpp:

#include "openglcanvas.h" 
#include "mainframe.h" 

... 

CMainFrame::CMainFrame(wxMenuBar* menu, const wxString& title, const wxPoint& pos, const wxSize& size) 
: wxFrame((wxFrame *)NULL, -1, title, pos, size) 
{ 
m_menu=menu; 

canvas = new OpenGLCanvas((wxWindow*)this,-1, pos , size, 0 , wxT("Canvas")); 
}//constructor 

... 

mainframe.h

#ifndef __MAINFRAME_H__ 
#define __MAINFRAME_H__ 

... 

class CMainFrame: public wxFrame { 

public: 
CMainFrame(wxMenuBar* menu,const wxString& title, const wxPoint& pos, const wxSize& size); 

我怎樣包含這個文件? (我對C++相當陌生,但對C不太熟悉) 對於我的問題的長度,我表示抱歉。任何想法都會有很大的幫助。

謝謝。

回答

2

既然你只持有一個指針,你不需要和acctualy不包括整個文件。

您只需要一個forward declaration「class CMainFrame」;

+0

非常感謝!經過一些調整,固定它:) – Luisjomen2a