Error: expected unqualified-id before numeric constant, simple code.

I'm trying to review coding of open of multiple forms in Code::Blocks with wxWidgets.(now CB 16.1/wxW 3.0.2)

So this code Works in an example app in my old XP PC (CB 13.12/wxW 3.0.2)

But using the same method in my new test project errors.
1
2
3
4
5
6
7
void _27_7Frame::OnButton2Click(wxCommandEvent& event)
{
    Form2* frm1 = new Form2(0);  // error: expected unqualified-id before numeric constant
                                 // error: expected initializer before numeric constant
    frm1->Show();   //error: base operand of '->' is not a pointer
    //SetTopwindow(frm);
}

Build log, carets indicate problems:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

mingw32-g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Wall -O2 -std=c++11 -IC:\wxWidgets-3.0.2\include -IC:\wxWidgets-3.0.2\lib\gcc_dll\mswu -IC:\wxWidgets-3.0.2\lib\gcc_dll\mswu -c C:\Users\Admin\Desktop\Briefcase\CPP_projects\CodeBlocks\727_7\_27_7App.cpp -o obj\Release\_27_7App.o
mingw32-g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DWXUSINGDLL -DwxUSE_UNICODE -Wall -O2 -std=c++11 -IC:\wxWidgets-3.0.2\include -IC:\wxWidgets-3.0.2\lib\gcc_dll\mswu -IC:\wxWidgets-3.0.2\lib\gcc_dll\mswu -c C:\Users\Admin\Desktop\Briefcase\CPP_projects\CodeBlocks\727_7\_27_7Main.cpp -o obj\Release\_27_7Main.o
In file included from C:/Program Files (x86)/CodeBlocks/MinGW/include/windows.h:77:0,
                 from C:\wxWidgets-3.0.2\include/wx/msw/wrapwin.h:65,
                 from C:\wxWidgets-3.0.2\include/wx/atomic.h:48,
                 from C:\wxWidgets-3.0.2\include/wx/sharedptr.h:14,
                 from C:\wxWidgets-3.0.2\include/wx/dialog.h:16,
                 from C:\wxWidgets-3.0.2\include/wx/msgdlg.h:18,
                 from C:\Users\Admin\Desktop\Briefcase\CPP_projects\CodeBlocks\727_7\_27_7Main.cpp:11:
C:\Users\Admin\Desktop\Briefcase\CPP_projects\CodeBlocks\727_7\_27_7Main.cpp: In member function 'void _27_7Frame::OnButton2Click(wxCommandEvent&)':
C:\Users\Admin\Desktop\Briefcase\CPP_projects\CodeBlocks\727_7\_27_7Main.cpp:129:12: error: expected unqualified-id before numeric constant
     Form2* frm1 = new Form2(0);
            ^
C:\Users\Admin\Desktop\Briefcase\CPP_projects\CodeBlocks\727_7\_27_7Main.cpp:129:12: error: expected initializer before numeric constant
C:\Users\Admin\Desktop\Briefcase\CPP_projects\CodeBlocks\727_7\_27_7Main.cpp:130:9: error: base operand of '->' is not a pointer
     frm1->Show();
         ^
Process terminated with status 1 (0 minute(s), 4 second(s))
3 error(s), 0 warning(s) (0 minute(s), 4 second(s))

Why would my Form2 being identified as an expected unqualified-id?
(I can post the full module code if desired)

Advice appreciated.
Last edited on
The compiler is complaining that Form2 is a numeric constant, not a type.
So I need to declare Form2 as a type?
And or find where it is declared as a numeric constant.

This is my full code, Main.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "_27_7Main.h"
#include <wx/msgdlg.h>
#include "Form2.h"

//(*InternalHeaders(_27_7Frame)
#include <wx/font.h>
#include <wx/intl.h>
#include <wx/string.h>

//*)

//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}

//(*IdInit(_27_7Frame)
const long _27_7Frame::ID_BUTTON1 = wxNewId();
const long _27_7Frame::ID_CHECKBOX1 = wxNewId();
const long _27_7Frame::ID_STATICTEXT1 = wxNewId();
const long _27_7Frame::ID_BUTTON2 = wxNewId();
const long _27_7Frame::idMenuQuit = wxNewId();
const long _27_7Frame::idMenuAbout = wxNewId();
const long _27_7Frame::ID_STATUSBAR1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(_27_7Frame,wxFrame)
    //(*EventTable(_27_7Frame)
    //*)
END_EVENT_TABLE()

_27_7Frame::_27_7Frame(wxWindow* parent,wxWindowID id)
{
    //(*Initialize(_27_7Frame)
    wxMenuItem* MenuItem2;
    wxMenuItem* MenuItem1;
    wxMenu* Menu1;
    wxMenuBar* MenuBar1;
    wxMenu* Menu2;

    Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
    SetClientSize(wxSize(400,215));
    SetBackgroundColour(wxColour(255,128,0));
    Button1 = new wxButton(this, ID_BUTTON1, _("Close"), wxPoint(312,176), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
    CheckBox1 = new wxCheckBox(this, ID_CHECKBOX1, _("Label"), wxPoint(136,104), wxDefaultSize, 0, wxDefaultValidator, _T("ID_CHECKBOX1"));
    CheckBox1->SetValue(false);
    StaticText1 = new wxStaticText(this, ID_STATICTEXT1, _("Last Test 27-Jul-2016"), wxPoint(88,48), wxDefaultSize, 0, _T("ID_STATICTEXT1"));
    wxFont StaticText1Font(18,wxFONTFAMILY_SWISS,wxFONTSTYLE_NORMAL,wxFONTWEIGHT_NORMAL,false,_T("Comic Sans MS"),wxFONTENCODING_DEFAULT);
    StaticText1->SetFont(StaticText1Font);
    Button2 = new wxButton(this, ID_BUTTON2, _("Form 2 Open"), wxPoint(88,160), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    SetMenuBar(MenuBar1);
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[1] = { -1 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(StatusBar1);

    Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&_27_7Frame::OnButton1Click);
    Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&_27_7Frame::OnButton2Click);
    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&_27_7Frame::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&_27_7Frame::OnAbout);
    //*)
}

_27_7Frame::~_27_7Frame()
{
    //(*Destroy(_27_7Frame)
    //*)
}

void _27_7Frame::OnQuit(wxCommandEvent& event)
{
    //Close();
}

void _27_7Frame::OnAbout(wxCommandEvent& event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}

void _27_7Frame::OnButton1Click(wxCommandEvent& event)
{
    Close();
}

void _27_7Frame::OnButton2Click(wxCommandEvent& event)
{
    Form2* frm1 = new Form2(0);  // error: expected unqualified-id before numeric constant
                                 // error: expected initializer before numeric constant
    frm1->Show();   //error: base operand of '->' is not a pointer 
}


The related Form2.h file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef FORM2_H
#define FORM2_H

//(*Headers(Form2)
#include <wx/stattext.h>
#include <wx/panel.h>
#include <wx/button.h>
#include <wx/frame.h>
//*)

class Form2: public wxFrame
{
	public:

		Form2(wxWindow* parent,wxWindowID id=wxID_ANY);
		virtual ~Form2();

		//(*Declarations(Form2)
		wxButton* Button1;
		wxPanel* Panel1;
		wxStaticText* StaticText1;
		//*)

	protected:

		//(*Identifiers(Form2)
		static const long ID_STATICTEXT1;
		static const long ID_BUTTON1;
		static const long ID_PANEL1;
		//*)

	private:

		//(*Handlers(Form2)
		void OnClose(wxCloseEvent& event);
		void OnButton1Click(wxCommandEvent& event);
		void OnButton1Click1(wxCommandEvent& event);
		//*)

		DECLARE_EVENT_TABLE()
};

#endif 
Last edited on
Maybe _27_7Frame defines something named Form2? What happens if inside _27_7Frame::OnButton2Click() you use ::Form2 instead of Form2?
Helios
I really appreciate your patience with my presentation, but its better.

In my button code I replaced frm1 with frm.
1
2
3
4
5
void _27_7Frame::OnButton2Click(wxCommandEvent& event)
{
    Form2* frm = new Form2(0);
    frm->Show(); 
}


Now have one error:
1
2
3
4
5
6
7


obj\Release\Form2.o:Form2.cpp:(.text+0xf52): undefined reference to `Form2::OnButton1Click1(wxCommandEvent&)'
collect2.exe: error: ld returned 1 exit status

Process terminated with status 1 (0 minute(s), 9 second(s))
2 error(s), 0 warning(s) (0 minute(s), 9 second(s))


Colons as such on both Form2, produced same error.
1
2
3
4
5
void _27_7Frame::OnButton2Click(wxCommandEvent& event)
{
    ::Form2* frm = new ::Form2(0);
    frm->Show(); 
}


I may have caused this by renaming the wxFrame initially...
Last edited on
Topic archived. No new replies allowed.