Initializer error in wxWidgets 3.0.3 when compiling with gcc v. 7.1 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
beneficii
Earned some good credits
Earned some good credits
Posts: 111
Joined: Fri Nov 27, 2009 2:49 am

Initializer error in wxWidgets 3.0.3 when compiling with gcc v. 7.1

Post by beneficii »

This is wxWidgets 3.0.3, compiled with g++ v. 7.1, on Ubuntu Linux v. 17.04.

Here is the definition of my frame class:

Code: Select all

class MyFrame : public wxFrame {
public:
    MyFrame();

private:
    wxTextCtrl *m_textedit;

};
Here is the implementation of its constructor:

Code: Select all

#define ID_TEXTEDIT 0x101

MyFrame::MyFrame() : 
    wxFrame(nullptr, wxID_ANY, "SimpleText"),
    m_textedit(this, ID_TEXTEDIT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 
        wxTE_MULTILINE | wxTE_RICH2 | wxTE_NOHIDESEL | wxTE_WORDWRAP)
{
    wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
    sizer->Add(m_textedit, 1, wxEXPAND);
    this->SetSizer(sizer);
}
And here is the error, which I don't really understand:

Code: Select all

frame.cpp: In constructor ‘MyFrame::MyFrame()’:
frame.cpp:14:65: error: expression list treated as compound expression in mem-initializer [-fpermissive]
     wxTE_MULTILINE | wxTE_RICH2 | wxTE_NOHIDESEL | wxTE_WORDWRAP)
                                                                 ^
frame.cpp:14:65: error: invalid conversion from ‘int’ to ‘wxTextCtrl*’ [-fpermissive]
The problem is apparently the one where I bitwise-OR a number of styles in the argument that corresponds with long style.

So why does the compiler think I'm trying to convert from int to wxTextCtrl*? I'm not really understanding the problem here.
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Initializer error in wxWidgets 3.0.3 when compiling with gcc v. 7.1

Post by doublemax »

You could only initialize "m_textedit" this way if it was of type "wxTextCtrl", but it's a pointer (and it has to be).

Move the initialization into the constructor.
Use the source, Luke!
beneficii
Earned some good credits
Earned some good credits
Posts: 111
Joined: Fri Nov 27, 2009 2:49 am

Re: Initializer error in wxWidgets 3.0.3 when compiling with gcc v. 7.1

Post by beneficii »

Dur.

I changed it to this:

Code: Select all

m_textedit(new wxTextCtrl(this, ID_TEXTEDIT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 
        wxTE_MULTILINE | wxTE_RICH2 | wxTE_NOHIDESEL | wxTE_WORDWRAP))
Thanks!
Post Reply