简体   繁体   中英

C++ including dependencies using wxWidgets and Opengl

I'm not quite sure if this should be consider as a C++ question or a wxWidgets:

I'm working on a fairly simple wxWidgets interface that will allow the user to draw triangles. 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. 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:

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);

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. 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.

You only need a forward declaration "class CMainFrame";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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