Error C2143 and C4430 on wxCustomButton 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.
User avatar
Ambush
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Jun 12, 2017 6:08 pm

Error C2143 and C4430 on wxCustomButton

Post by Ambush »

Hi all

I am trying to understand how to add custom buttons to my very basic app,
i have managed to add the custom button tutorial to the app in vs2013, all appears good,
untill i try to debug at which point it throws the errors in the post title the more detailed
description is as follows.
main.h(10): error C2143: syntax error : missing ';' before '*'
main.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
i am certain i either have something in the wrong place, or have missed something like a decalaration out
but dont know what, hopefully one of you can spot it as i have searched but cant find a solution due my inexperience.

custombutton.h

Code: Select all

#include <wx\wx.h>

class wxCustomButton : public wxWindow
{

	bool pressedDown;
	wxString text;

	static const int buttonWidth = 200;
	static const int buttonHeight = 50;

public:
	wxCustomButton(wxFrame* parent, wxString text);

	void paintEvent(wxPaintEvent & evt);
	void paintNow();

	void render(wxDC& dc);
	
	DECLARE_EVENT_TABLE()
	
	// some useful events
	void mouseMoved(wxMouseEvent& event);
	void mouseDown(wxMouseEvent& event);
	void mouseWheelMoved(wxMouseEvent& event);
	void mouseReleased(wxMouseEvent& event);
	void rightClick(wxMouseEvent& event);
	void mouseLeftWindow(wxMouseEvent& event);
	void keyPressed(wxKeyEvent& event);
	void keyReleased(wxKeyEvent& event);
};


BEGIN_EVENT_TABLE(wxCustomButton, wxPanel)

EVT_MOTION(wxCustomButton::mouseMoved)
EVT_LEFT_DOWN(wxCustomButton::mouseDown)
EVT_LEFT_UP(wxCustomButton::mouseReleased)
EVT_RIGHT_DOWN(wxCustomButton::rightClick)
EVT_LEAVE_WINDOW(wxCustomButton::mouseLeftWindow)
EVT_KEY_DOWN(wxCustomButton::keyPressed)
EVT_KEY_UP(wxCustomButton::keyReleased)
EVT_MOUSEWHEEL(wxCustomButton::mouseWheelMoved)

// catch paint events
EVT_PAINT(wxCustomButton::paintEvent)

END_EVENT_TABLE()
custombutton.cpp

Code: Select all

#include "CustomButton.h"

wxCustomButton::wxCustomButton(wxFrame* parent, wxString text) :
wxWindow(parent, wxID_ANY)
{
	SetMinSize(wxSize(buttonWidth, buttonHeight));
	this->text = text;
	pressedDown = false;
};

void wxCustomButton::paintEvent(wxPaintEvent & evt)
{
	wxPaintDC dc(this);
	render(dc);
};

void wxCustomButton::paintNow()
{
	wxClientDC dc(this);
	render(dc);
};

void wxCustomButton::render(wxDC&  dc)
{
	if (pressedDown)
		dc.SetBrush(*wxRED_BRUSH);
	else
		dc.SetBrush(*wxGREY_BRUSH);

	dc.DrawRectangle(0, 0, buttonWidth, buttonHeight);
	dc.DrawText(text, 20, 15);
};

void wxCustomButton::mouseDown(wxMouseEvent& event)
{
	pressedDown = true;
	paintNow();
};

void wxCustomButton::mouseReleased(wxMouseEvent& event)
{
	pressedDown = false;
	paintNow();

	wxMessageBox(wxString("You pressed a custom button"));
};
void wxCustomButton::mouseLeftWindow(wxMouseEvent& event)
{
	if (pressedDown)
	{
		pressedDown = false;
		paintNow();
	}
};

// currently unused events
void wxCustomButton::mouseMoved(wxMouseEvent& event) {}
void wxCustomButton::mouseWheelMoved(wxMouseEvent& event) {}
void wxCustomButton::rightClick(wxMouseEvent& event) {}
void wxCustomButton::keyPressed(wxKeyEvent& event) {}
void wxCustomButton::keyReleased(wxKeyEvent& event) {}
main.h

Code: Select all

#include <wx\wx.h>


class Main : public wxApp
{
public: 
	virtual bool OnInit();
		
	wxFrame *frame;
	wxCustomButton *btnexit;
};

DECLARE_APP(Main)
main.cpp

Code: Select all

#include "Main.h"
#include "CustomButton.h"

IMPLEMENT_APP(Main)

bool Main::OnInit()
{
	wxInitAllImageHandlers();

	frame = new wxFrame(NULL, wxID_ANY, wxString("Title"), wxPoint(wxDefaultPosition), wxSize(0, 0));

	wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);

	wxCustomButton *btnexit = new wxCustomButton(frame, "my button");
	sizer->Add(btnexit);

	frame->SetSizerAndFit(sizer);
	frame->Center();
	frame->Show();

	return true;

};
rather annoyingly i had this working origionally as was in the tutorial, but have no idea what i have done to it.

thanks
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Error C2143 and C4430 on wxCustomButton

Post by ONEEYEMAN »

Hi,
In the main.cpp:

Code: Select all

#include "CustomButton.h"
#include "Main.h"
Thank you.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Error C2143 and C4430 on wxCustomButton

Post by PB »

Have you tried including "CustomButton.h" in "Main.h" instead of "Main.cpp". BTW, it's a good practice to add guards against multiple inclusion to your header files...

Also, I have never used event tables but it seems odd that CustomButton derives from wxWindow yet you have wxPanel in the event table as the base class....
User avatar
Ambush
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Jun 12, 2017 6:08 pm

Re: Error C2143 and C4430 on wxCustomButton

Post by Ambush »

hi guys thanks for your reply, i will check this out now

i also have tried this using both wxpanel and wxwindow, and it gave me the same error on both iirc,
i will let you know how i get on.

tnx
User avatar
Ambush
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Jun 12, 2017 6:08 pm

Re: Error C2143 and C4430 on wxCustomButton

Post by Ambush »

ok what i have done it to change the header files as recommended and again tried
using wxWindow as opposed to wxPanel, the error given this time is as follows.
1>Main.obj : error LNK2005: "protected: virtual class wxEventHashTable & __thiscall wxCustomButton::GetEventHashTable(void)const " (?GetEventHashTable@wxCustomButton@@MBEAAVwxEventHashTable@@XZ) already defined in CustomButton.obj
1>Main.obj : error LNK2005: "protected: virtual struct wxEventTable const * __thiscall wxCustomButton::GetEventTable(void)const " (?GetEventTable@wxCustomButton@@MBEPBUwxEventTable@@XZ) already defined in CustomButton.obj
1>Main.obj : error LNK2005: "protected: static struct wxEventTable const wxCustomButton::sm_eventTable" (?sm_eventTable@wxCustomButton@@1UwxEventTable@@B) already defined in CustomButton.obj
1>Main.obj : error LNK2005: "private: static struct wxEventTableEntry const * const wxCustomButton::sm_eventTableEntries" (?sm_eventTableEntries@wxCustomButton@@0QBUwxEventTableEntry@@B) already defined in CustomButton.obj
1>Main.obj : error LNK2005: "protected: static class wxEventHashTable wxCustomButton::sm_eventHashTable" (?sm_eventHashTable@wxCustomButton@@1VwxEventHashTable@@A) already defined in CustomButton.obj
1>C:\Users\Administrator\wxProjects\wxCustomButton\Debug\wxCustomButton.exe : fatal error LNK1169: one or more multiply defined symbols found
i see something is already defined, but again dont really understand it
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Error C2143 and C4430 on wxCustomButton

Post by ONEEYEMAN »

Hi,
Put you

Code: Select all

BEGIN_EVENT_TABLE()
........
END_EVENT_TABLE()
block in the .cpp file.

Those lines are not declaration but definition and therefore belongs to source code rather than the header.

BTW, what book you are looking at?

Thank you.
User avatar
Ambush
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Jun 12, 2017 6:08 pm

Re: Error C2143 and C4430 on wxCustomButton

Post by Ambush »

tnx, i will have a look at that as well.

the place i am getting it from is https://wiki.wxwidgets.org/Painting_your_custom_control
User avatar
Ambush
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Jun 12, 2017 6:08 pm

Re: Error C2143 and C4430 on wxCustomButton

Post by Ambush »

:( unfortunatly its still not working, i think i am getting a slightly different error now.
i am going to leave this for tonight and have another go tmw and will post what i find.

the error given is
1> CustomButton.cpp
1>CustomButton.obj : error LNK2019: unresolved external symbol "protected: void __thiscall wxCustomButton::mouseMoved(class wxMouseEvent &)" (?mouseMoved@wxCustomButton@@IAEXAAVwxMouseEvent@@@Z) referenced in function "void __cdecl `dynamic initializer for 'private: static struct wxEventTableEntry const * const wxCustomButton::sm_eventTableEntries''(void)" (??__E?sm_eventTableEntries@wxCustomButton@@0QBUwxEventTableEntry@@B@@YAXXZ)
1>CustomButton.obj : error LNK2019: unresolved external symbol "protected: void __thiscall wxCustomButton::mouseWheelMoved(class wxMouseEvent &)" (?mouseWheelMoved@wxCustomButton@@IAEXAAVwxMouseEvent@@@Z) referenced in function "void __cdecl `dynamic initializer for 'private: static struct wxEventTableEntry const * const wxCustomButton::sm_eventTableEntries''(void)" (??__E?sm_eventTableEntries@wxCustomButton@@0QBUwxEventTableEntry@@B@@YAXXZ)
1>CustomButton.obj : error LNK2019: unresolved external symbol "protected: void __thiscall wxCustomButton::rightClick(class wxMouseEvent &)" (?rightClick@wxCustomButton@@IAEXAAVwxMouseEvent@@@Z) referenced in function "void __cdecl `dynamic initializer for 'private: static struct wxEventTableEntry const * const wxCustomButton::sm_eventTableEntries''(void)" (??__E?sm_eventTableEntries@wxCustomButton@@0QBUwxEventTableEntry@@B@@YAXXZ)
1>CustomButton.obj : error LNK2019: unresolved external symbol "protected: void __thiscall wxCustomButton::keyPressed(class wxKeyEvent &)" (?keyPressed@wxCustomButton@@IAEXAAVwxKeyEvent@@@Z) referenced in function "void __cdecl `dynamic initializer for 'private: static struct wxEventTableEntry const * const wxCustomButton::sm_eventTableEntries''(void)" (??__E?sm_eventTableEntries@wxCustomButton@@0QBUwxEventTableEntry@@B@@YAXXZ)
1>CustomButton.obj : error LNK2019: unresolved external symbol "protected: void __thiscall wxCustomButton::keyReleased(class wxKeyEvent &)" (?keyReleased@wxCustomButton@@IAEXAAVwxKeyEvent@@@Z) referenced in function "void __cdecl `dynamic initializer for 'private: static struct wxEventTableEntry const * const wxCustomButton::sm_eventTableEntries''(void)" (??__E?sm_eventTableEntries@wxCustomButton@@0QBUwxEventTableEntry@@B@@YAXXZ)
1>C:\Users\Administrator\wxProjects\wxCustomButton\Debug\wxCustomButton.exe : fatal error LNK1120: 5 unresolved externals
tnx !
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Error C2143 and C4430 on wxCustomButton

Post by doublemax »

The event table should be in the .cpp file, not the header file.

Code: Select all

BEGIN_EVENT_TABLE(wxCustomButton, wxPanel)
Also, as PB already mentioned, the "wxPanel" here should be "wxWindow" in your case, as that's the base class you're using. (Yes, that's also wrong on the wiki page).
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Error C2143 and C4430 on wxCustomButton

Post by ONEEYEMAN »

Hi,
Could you please post the modified sources? It is hard to do a guess game here...

Thank you.
User avatar
Ambush
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Jun 12, 2017 6:08 pm

Re: Error C2143 and C4430 on wxCustomButton

Post by Ambush »

mornin all, i will post the modified code below

custombutton.h

Code: Select all

#include <wx\wx.h>

class wxCustomButton : public wxWindow
{

	bool pressedDown;
	wxString text;

	static const int buttonWidth = 200;
	static const int buttonHeight = 50;

public:
	wxCustomButton(wxFrame* parent, wxString text);

	void paintEvent(wxPaintEvent & evt);
	void paintNow();

	void render(wxDC& dc);
	
	DECLARE_EVENT_TABLE()
	
	// some useful events
	void mouseMoved(wxMouseEvent& event);
	void mouseDown(wxMouseEvent& event);
	void mouseWheelMoved(wxMouseEvent& event);
	void mouseReleased(wxMouseEvent& event);
	void rightClick(wxMouseEvent& event);
	void mouseLeftWindow(wxMouseEvent& event);
	void keyPressed(wxKeyEvent& event);
	void keyReleased(wxKeyEvent& event);
};
custombutton.cpp

Code: Select all

#include "CustomButton.h"

BEGIN_EVENT_TABLE(wxCustomButton, wxWindow)

EVT_MOTION(wxCustomButton::mouseMoved)
EVT_LEFT_DOWN(wxCustomButton::mouseDown)
EVT_LEFT_UP(wxCustomButton::mouseReleased)
EVT_RIGHT_DOWN(wxCustomButton::rightClick)
EVT_LEAVE_WINDOW(wxCustomButton::mouseLeftWindow)
EVT_KEY_DOWN(wxCustomButton::keyPressed)
EVT_KEY_UP(wxCustomButton::keyReleased)
EVT_MOUSEWHEEL(wxCustomButton::mouseWheelMoved)

// catch paint events
EVT_PAINT(wxCustomButton::paintEvent)

END_EVENT_TABLE()

wxCustomButton::wxCustomButton(wxFrame* parent, wxString text) :
wxWindow(parent, wxID_ANY)
{
	SetMinSize(wxSize(buttonWidth, buttonHeight));
	this->text = text;
	pressedDown = false;
};

void wxCustomButton::paintEvent(wxPaintEvent & evt)
{
	wxPaintDC dc(this);
	render(dc);
};

void wxCustomButton::paintNow()
{
	wxClientDC dc(this);
	render(dc);
};

void wxCustomButton::render(wxDC&  dc)
{
	if (pressedDown)
		dc.SetBrush(*wxRED_BRUSH);
	else
		dc.SetBrush(*wxGREY_BRUSH);

	dc.DrawRectangle(0, 0, buttonWidth, buttonHeight);
	dc.DrawText(text, 20, 15);
};

void wxCustomButton::mouseDown(wxMouseEvent& event)
{
	pressedDown = true;
	paintNow();
};

void wxCustomButton::mouseReleased(wxMouseEvent& event)
{
	pressedDown = false;
	paintNow();

	wxMessageBox(wxString("You pressed a custom button"));
};
void wxCustomButton::mouseLeftWindow(wxMouseEvent& event)
{
	if (pressedDown)
	{
		pressedDown = false;
		paintNow();
	}
};



// currently unused events
//void wxCustomButton::mouseMoved(wxMouseEvent& event) {}
//void wxCustomButton::mouseWheelMoved(wxMouseEvent& event) {}
//void wxCustomButton::rightClick(wxMouseEvent& event) {}
//void wxCustomButton::keyPressed(wxKeyEvent& event) {}
//void wxCustomButton::keyReleased(wxKeyEvent& event) {}


main.h

Code: Select all

#include <wx\wx.h>
#include "CustomButton.h"

class Main : public wxApp
{
public: 
	virtual bool OnInit();
		
	wxFrame *frame;
	wxCustomButton *btnexit;
};

DECLARE_APP(Main)
main.cpp

Code: Select all

#include "Main.h"

IMPLEMENT_APP(Main)

bool Main::OnInit()
{
	wxInitAllImageHandlers();

	frame = new wxFrame(NULL, wxID_ANY, wxString("Title"), wxPoint(wxDefaultPosition), wxSize(0, 0));

	wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);

	wxCustomButton *btnexit = new wxCustomButton(frame, "my button");
	sizer->Add(btnexit);

	frame->SetSizerAndFit(sizer);
	frame->Center();
	frame->Show();

	return true;

};
hopefully this helps !
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Error C2143 and C4430 on wxCustomButton

Post by doublemax »

What error messages do you get now? With the event table in the right place, it should be fewer or different ones.
Use the source, Luke!
User avatar
Ambush
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Jun 12, 2017 6:08 pm

Re: Error C2143 and C4430 on wxCustomButton

Post by Ambush »

hi,

this is the given error
1>CustomButton.obj : error LNK2019: unresolved external symbol "protected: void __thiscall wxCustomButton::mouseMoved(class wxMouseEvent &)" (?mouseMoved@wxCustomButton@@IAEXAAVwxMouseEvent@@@Z) referenced in function "void __cdecl `dynamic initializer for 'private: static struct wxEventTableEntry const * const wxCustomButton::sm_eventTableEntries''(void)" (??__E?sm_eventTableEntries@wxCustomButton@@0QBUwxEventTableEntry@@B@@YAXXZ)
1>CustomButton.obj : error LNK2019: unresolved external symbol "protected: void __thiscall wxCustomButton::mouseWheelMoved(class wxMouseEvent &)" (?mouseWheelMoved@wxCustomButton@@IAEXAAVwxMouseEvent@@@Z) referenced in function "void __cdecl `dynamic initializer for 'private: static struct wxEventTableEntry const * const wxCustomButton::sm_eventTableEntries''(void)" (??__E?sm_eventTableEntries@wxCustomButton@@0QBUwxEventTableEntry@@B@@YAXXZ)
1>CustomButton.obj : error LNK2019: unresolved external symbol "protected: void __thiscall wxCustomButton::rightClick(class wxMouseEvent &)" (?rightClick@wxCustomButton@@IAEXAAVwxMouseEvent@@@Z) referenced in function "void __cdecl `dynamic initializer for 'private: static struct wxEventTableEntry const * const wxCustomButton::sm_eventTableEntries''(void)" (??__E?sm_eventTableEntries@wxCustomButton@@0QBUwxEventTableEntry@@B@@YAXXZ)
1>CustomButton.obj : error LNK2019: unresolved external symbol "protected: void __thiscall wxCustomButton::keyPressed(class wxKeyEvent &)" (?keyPressed@wxCustomButton@@IAEXAAVwxKeyEvent@@@Z) referenced in function "void __cdecl `dynamic initializer for 'private: static struct wxEventTableEntry const * const wxCustomButton::sm_eventTableEntries''(void)" (??__E?sm_eventTableEntries@wxCustomButton@@0QBUwxEventTableEntry@@B@@YAXXZ)
1>CustomButton.obj : error LNK2019: unresolved external symbol "protected: void __thiscall wxCustomButton::keyReleased(class wxKeyEvent &)" (?keyReleased@wxCustomButton@@IAEXAAVwxKeyEvent@@@Z) referenced in function "void __cdecl `dynamic initializer for 'private: static struct wxEventTableEntry const * const wxCustomButton::sm_eventTableEntries''(void)" (??__E?sm_eventTableEntries@wxCustomButton@@0QBUwxEventTableEntry@@B@@YAXXZ)
1>C:\Users\Administrator\wxProjects\wxCustomButton\Debug\wxCustomButton.exe : fatal error LNK1120: 5 unresolved externals
i can also attach the files, if you need them just let me know.
User avatar
Ambush
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Jun 12, 2017 6:08 pm

Re: Error C2143 and C4430 on wxCustomButton

Post by Ambush »

The files
Attachments
Main.h
(186 Bytes) Downloaded 69 times
Main.cpp
(485 Bytes) Downloaded 68 times
CustomButton.h
(767 Bytes) Downloaded 76 times
User avatar
Ambush
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Jun 12, 2017 6:08 pm

Re: Error C2143 and C4430 on wxCustomButton

Post by Ambush »

missing file
Attachments
CustomButton.cpp
(1.45 KiB) Downloaded 68 times
Post Reply