【问题标题】:C++ including dependencies using wxWidgets and OpenglC++ 包括使用 wxWidgets 和 Opengl 的依赖项
【发布时间】:2012-10-24 10:31:08
【问题描述】:

我不太确定这应该被视为 C++ 问题还是 wxWidgets:

我正在开发一个相当简单的 wxWidgets 界面,它允许用户绘制三角形。 因此,我有一个画布(OpenGLCanvas 类)和一个 wxWindow(CMainFrame 类),问题是我希望我的画布有一个窗口实例,反之亦然。错误的根源是,当编译器到达我的 CMainFrame 实例所在的 OpenGLCanvas 部分时,它(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 不熟悉) 我为我的问题的长度道歉。任何想法都会有很大帮助。

谢谢。

【问题讨论】:

    标签: c++ opengl wxwidgets


    【解决方案1】:

    由于您只持有不需要的指针,因此不建议将整个文件包含在内。

    你只需要一个forward declaration "class CMainFrame";

    【讨论】:

    • 非常感谢!经过一些调整以修复它:)
    猜你喜欢
    • 2014-08-20
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2016-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多