简体   繁体   English

C ++包括使用wxWidgets和Opengl的依赖项

[英]C++ including dependencies using wxWidgets and Opengl

I'm not quite sure if this should be consider as a C++ question or a wxWidgets: 我不太确定这应该被视为C ++问题还是wxWidgets:

I'm working on a fairly simple wxWidgets interface that will allow the user to draw triangles. 我正在开发一个相当简单的wxWidgets接口,允许用户绘制三角形。 Thus, I have a canvas (OpenGLCanvas class) and a wxWindow (CMainFrame class) the problem is that I want my canvas to have an instance of my window and vice versa. 因此,我有一个画布(OpenGLCanvas类)和一个wxWindow(CMainFrame类),问题是我希望我的画布有一个窗口的实例,反之亦然。 The source of the error is that for the time the compiler has reached the part of the OpenGLCanvas where my CMainFrame instance is, it(the CMainFrame) has not been defined and the same thing happens if I change the order of the #includes here is my code: 错误的来源是,当编译器到达我的CMainFrame实例所在的OpenGLCanvas的一部分时,它(CMainFrame)尚未定义,如果我更改#includes的顺序,则会发生同样的事情。我的代码:

OpenGLCanvas.cpp: 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: 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: 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 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);

How am I supposed to include this files? 我该如何包含这些文件? (I am fairly new to C++ but not to C) I apologize for the length of my question. (我对C ++很新,但不是C)我为问题的长度道歉。 Any ideas would be of great help. 任何想法都会有很大的帮助。

Thank you. 谢谢。

Since you only hold a pointer you don;t need and acctualy is NOT recommended to include the whole file. 由于你只持有一个指针,你不需要和acctualy不建议包括整个文件。

You only need a forward declaration "class CMainFrame"; 你只需要一个前向声明 “class CMainFrame”;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM