"does not name a type" error with glCanvas Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
almonj
Earned a small fee
Earned a small fee
Posts: 16
Joined: Fri Dec 09, 2016 5:41 pm

"does not name a type" error with glCanvas

Post by almonj »

I am trying to write a glCanvas class but I keep getting "does not name a type" errors. If I exclude the M_canvas files the frame class runs and works, but when I add the M_canvas files it gives me the errors:

\M_canvas.h|15|error: expected ')' before '*' token|

\M_canvas.h|19|error: 'M_frame' does not name a type|

I don't understand why it does not recognize the class if I have the header included. Can I not use my M_frame class as a wxWindow type in the glCanvas constructor?


M_canvas.h

Code: Select all

#ifndef M_CANVAS_H
#define M_CANVAS_H

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

class M_canvas : public wxGLCanvas
{
public:
    M_canvas(M_frame* parent, const wxGLAttributes& attribs);
    ~M_canvas(){};

private:
    M_frame* m_parent;
    wxGLContext* m_context;

    wxDECLARE_EVENT_TABLE();

};
M_canvas.cc

Code: Select all

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

M_canvas::M_canvas(M_frame* parent, const wxGLAttributes& attribs)
         : wxGLCanvas(parent, attribs, wxID_ANY, wxDefaultPosition, wxDefaultSize, NULL, "canvas", wxNullPalette)
{
    m_parent = parent;
    wxGLContextAttrs ctxAttribs;

};

BEGIN_EVENT_TABLE(M_canvas, wxFrame)

END_EVENT_TABLE()
M_frame.h

Code: Select all

#ifndef M_FRAME_H
#define M_FRAME_H

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

#include "M_canvas.h"

class M_frame : public wxFrame
{
public:
    M_frame(const wxString& title);
    virtual ~M_frame() {};

    void OnQuit(wxCommandEvent& event);

private:
    M_canvas* canvas;

    DECLARE_EVENT_TABLE();
};

#endif // M_FRAME_H
M_frame.cc

Code: Select all

#include "wx/wx.h"
#include "m_frame.h"


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


M_frame::M_frame(const wxString& title)
       : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(800, 600))
{

    canvas = NULL;
    wxGLAttributes attribs;
    attribs.PlatformDefaults().Defaults().EndList();

    wxMenu    *menufile    = new wxMenu;
    wxMenuBar *menubar     = new wxMenuBar;

    menubar->Append(menufile, "&File");

    menufile->Append(wxID_EXIT);
    menufile->AppendSeparator();


    SetMenuBar(menubar);


};

void M_frame::OnQuit(wxCommandEvent& event)
{
    Close(TRUE);
}


BEGIN_EVENT_TABLE(M_frame, wxFrame)
    EVT_MENU(wxID_EXIT, M_frame::OnQuit)
END_EVENT_TABLE()

Init.h

Code: Select all

#ifndef INIT_H
#define INIT_H



class Init : public wxApp
{
public:
    Init(){};
    bool OnInit() wxOVERRIDE;

};

#endif // INIT_H

Init.cc

Code: Select all

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

#include "Init.h"
#include "M_frame.h"
#include "M_canvas.h"

IMPLEMENT_APP(Init);

bool Init::OnInit()
{

    if ( !wxApp::OnInit() )
        return false;

    M_frame* frame = new M_frame("main frame");

    frame->Show(true);

    return true;
}
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7449
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: "does not name a type" error with glCanvas

Post by ONEEYEMAN »

Hi,
Look at the M_canvas.cc and how you include the files in it.

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: "does not name a type" error with glCanvas

Post by doublemax »

The problem is that "M_frame.h" and "M_canvas.h" include each other.

Instead of including "M_frame.h" inside "M_canvas.h", use a forward reference:

Code: Select all

#ifndef M_CANVAS_H
#define M_CANVAS_H

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

class M_frame; // as long as you only use a pointer to M_frame below, the compiler doesn't need to know everything about "M_frame". Just knowing that it exists, is enough.

class M_canvas : public wxGLCanvas
{
public:
    M_canvas(M_frame* parent, const wxGLAttributes& attribs);
    ~M_canvas(){};

private:
    M_frame* m_parent;
    wxGLContext* m_context;
    wxDECLARE_EVENT_TABLE();
};
Use the source, Luke!
almonj
Earned a small fee
Earned a small fee
Posts: 16
Joined: Fri Dec 09, 2016 5:41 pm

Re: "does not name a type" error with glCanvas

Post by almonj »

That worked, thank you.
Post Reply