Can't Do a Dialog? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Can't Do a Dialog?

Post by FlyingIsFun1217 »

Hey, I'm back at it after a long break from wxWidgets. Anyway, I've got files set up to compile, the idea being that upon clicking a button on the main frame of my app, a dialog opens. Problem is, I keep getting errors, and cannot seem to set it up to correcly compile. Here are the files:

Code: Select all

//main.h
class Simple : public wxFrame
{
	public:
		Simple(const wxString& title);

		void AddSymbol(wxCommandEvent& event);
        protected:
                DECLARE_EVENT_TABLE()
};

class MyApp : public wxApp
{
	public:
		virtual bool OnInit();
};

Code: Select all

//main.cpp
#include "main.h"
#include "AddDialog.h"

Simple::Simple(const wxString& title) : wxFrame(NULL, -1, title, wxDefaultPosition, wxSize(600, 400))
{
	AddButton = new wxButton( this, 1002, wxT("Add Symbol"), wxDefaultPosition, wxDefaultSize, 0 );
}

void Simple::AddSymbol(wxCommandEvent& WXUNUSED(event))
{
	AddDialog *dialog = new AddDialog(this);
	dialog -> Show(true);
}

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
	Simple *simple = new Simple(wxT("Stock Ticker"));
	simple->Show(true);

	return true;
}

BEGIN_EVENT_TABLE(Simple, wxFrame)
	EVT_BUTTON(1002, Simple::AddSymbol)
END_EVENT_TABLE()

Code: Select all

//AddDialog.h
#include <wx/wx.h>
#include <wx/dialog.h>
#include "AddDialog.cpp"

class AddDialog : public wxDialog
{
	public:
		AddDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Add Stock Symbol"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE ); 
		~AddDialog();
};

Code: Select all

//AddDialog.cpp
#include <wx/wx.h>

AddDialog::AddDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{
	//
}

AddDialog::~AddDialog()
{
}
Without fail, when passing "g++ `wx-config --cxxflags` -o finance source/main.cpp `wx-config --libs`" through the command line, g++ complains and says this:
In file included from source/AddDialog.h:6:0,
from source/main.cpp:2:
source/AddDialog.cpp:3:1: error: ‘AddDialog’ does not name a type
In file included from source/AddDialog.h:6:0,
from source/main.cpp:2:
source/AddDialog.cpp:28:1: error: ‘AddDialog’ does not name a type
I cannot for the life of me figure out why it can't see AddDialog. It was included in main.cpp, it should see the class, right?!

FlyingIsFun1217
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Can't Do a Dialog?

Post by utelle »

FlyingIsFun1217 wrote:Problem is, I keep getting errors, and cannot seem to set it up to correcly compile. Here are the files:

Code: Select all

//AddDialog.h
#include <wx/wx.h>
#include <wx/dialog.h>
#include "AddDialog.cpp"

class AddDialog : public wxDialog
{
	public:
		AddDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Add Stock Symbol"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE ); 
		~AddDialog();
};

Code: Select all

//AddDialog.cpp
#include <wx/wx.h>

AddDialog::AddDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{
	//
}

AddDialog::~AddDialog()
{
}
Without fail, when passing "g++ `wx-config --cxxflags` -o finance source/main.cpp `wx-config --libs`" through the command line, g++ complains and says this:
In file included from source/AddDialog.h:6:0,
from source/main.cpp:2:
source/AddDialog.cpp:3:1: error: ‘AddDialog’ does not name a type
In file included from source/AddDialog.h:6:0,
from source/main.cpp:2:
source/AddDialog.cpp:28:1: error: ‘AddDialog’ does not name a type
I cannot for the life of me figure out why it can't see AddDialog. It was included in main.cpp, it should see the class, right?!
Well, in file AddDialog.h you include file AddDialog.cpp BEFORE the definition of class AddDialog. How is this supposed to work? No wonder the compiler complains.

You could move the #include line behind the class definition or you could include AddDialog.h in file AddDialog.cpp and compile AddDialog.cpp separately.

Regards,
Ulrich
FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Re: Can't Do a Dialog?

Post by FlyingIsFun1217 »

utelle wrote:you could include AddDialog.h in file AddDialog.cpp and compile AddDialog.cpp separately.
That did the trick. I was being a bit naive to the process because prior to this, I had always compiled in an IDE, which took care of adding sources to a makefile, and now I'm doing it by hand.

Thanks!
FlyingIsFun1217
Post Reply