0

これをC++の質問と見なすべきか、wxWidgetsと見なすべきかはよくわかりません。

私は、ユーザーが三角形を描くことができる、かなり単純なwxWidgetsインターフェースに取り組んでいます。したがって、キャンバス(OpenGLCanvasクラス)​​とwxWindow(CMainFrameクラス)があります。問題は、キャンバスにウィンドウのインスタンスを持たせたいということです。その逆も同様です。エラーの原因は、コンパイラがOpenGLCanvasのCMainFrameインスタンスがある部分に到達したとき、それ(CMainFrame)が定義されていないことです。ここで、#includesの順序を変更すると、同じことが起こります。私のコード:

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には慣れていません)質問が長かったことをお詫びします。どんなアイデアも大いに役立ちます。

ありがとうございました。

4

1 に答える 1

2

ポインタを保持するだけなので、必要ありません。実際には、ファイル全体を含めることはお勧めしません。

前方宣言「classCMainFrame」のみが必要です。

于 2012-11-04T10:26:12.320 に答える