使mysqlpp :: Connection对象成为wxFrame类对象的私有成员

时间:2015-03-13 04:21:06

标签: c++ g++ mysql++

我在尝试构建具有mysqlpp :: Connection对象作为我的wxFrame对象的私有成员的代码时遇到错误。

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


        wxDECLARE_EVENT_TABLE();        
};

G ++会出现以下错误。

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();
  ^

此下面还有其他代码尝试为对象调用connect()disconnect()方法,但正如错误所示,这是无法识别的。

即使我使用以下内容......

mysqlpp::Connection conn();

...允许构造函数使用默认初始化,编译器仍会抛出除第31行之外的所有错误。

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

这个字段声明似乎很奇怪。

mysqlpp::Connection conn(false);

尝试mysqlpp::Connection conn;并在构造函数的初始化列表中初始化它。