c++g++mysql++

Make mysqlpp::Connection object private member of wxFrame class object


I'm getting errors trying to build code that has a mysqlpp::Connection object as a private member of my wxFrame object.

class MyFrame: public wxFrame
{
    public:
        MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
    private:
        mysqlpp::Connection conn(false);


        wxDECLARE_EVENT_TABLE();        
};

G++ gives the following errors.

C:\TestApp\testapp.cpp:31:28: error: expected identifier before 'false'
   mysqlpp::Connection conn(false);
                        ^
C:\TestApp\testapp.cpp:31:28: error: expected ',' or '...' before 'false'
C:\TestApp\testapp.cpp: In member function 'int MyFrame::Initialization()':
C:\TestApp\testapp.cpp:102:6: error: '((MyFrame*)this)->MyFrame::conn' does not have class type
  if (conn.connect("xxxxxxxxxxx", "localhost", "xxxx", "xxxxxxxx", xxxx))
      ^
C:\TestApp\testapp.cpp:104:26: error: '((MyFrame*)this)->MyFrame::conn' does not have class type
   mysqlpp::Query query = conn.query("SELECT xxxxxxxxxxxxxx FROM xxxxxxxxxxx");
                          ^
C:\TestApp\testapp.cpp: In member function 'void MyFrame::OnClose(wxCloseEvent&)':
C:\TestApp\testapp.cpp:136:2: error: '((MyFrame*)this)->MyFrame::conn' does not have class type
  conn.disconnect();
  ^
C:\TestApp\testapp.cpp: In member function 'void MyFrame::OnExit(wxCommandEvent&)':
C:\TestApp\testapp.cpp:143:2: error: '((MyFrame*)this)->MyFrame::conn' does not have class type
  conn.disconnect();
  ^

There is other code below this that attempts to call the connect() and disconnect() methods for the object, but as the errors indicate, this is not recognized.

Even when I use the following...

mysqlpp::Connection conn();

... allowing the constructor to use the default initialization, the compiler still throws all of the errors except those for line 31.

Any ideas?


Solution

  • This field declaration seems weird.

    mysqlpp::Connection conn(false);
    

    Try mysqlpp::Connection conn; and initialize it within initializer list in constructor.