wxWidgets中的一个小问题,问题在完整源代码中

name61 2010-06-17 09:08:33

#include <wx/wx.h>
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};

class MyFrame : public wxFrame
{
public:
MyFrame(const wxString & title);
void OnQuit(wxCommandEvent & event);
void OnAbout(wxCommandEvent & event);
private :
DECLARE_EVENT_TABLE()
};

DECLARE_APP(MyApp)
IMPLIMENT_APP(MyApp)

bool MyApp::OnInit()//问题就出在这儿 编译后的提示是:
//error: expected constructor, destructor, or type conversion before "bool"


{
MyFrame *frame = new MyFrame(wxT("Minimal wxWidget App"));
frame->Show(true);
return true;
}

BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
END_EVENT_TABLE()

void MyFrame::OnAbout(wxCommandEvent & event)
{
wxString msg;
msg.Printf(wxT("Hello and Welcome to %s"),
wxVERSION_STRING);

wxMessageBox(msg, wxT("About Minimal"),
wxOK|wxICON_INFORMATION,this);
}

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

#include "mondrian.xpm"

MyFrame::MyFrame(const wxString & title)
:wxFrame(NULL, wxID_ANY, title)
...全文
159 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
name61 2010-06-29
  • 打赏
  • 举报
回复
有扩展库的话,是没有代码自动完成吧
cblcz 2010-06-26
  • 打赏
  • 举报
回复
我都是代码自动完成,o(∩_∩)o 没这种错误
cblcz 2010-06-26
  • 打赏
  • 举报
回复

IMPLIMENT_APP(MyApp)改为 IMPLEMENT_APP(MyApp)


囧...果然眼力还是不行
name61 2010-06-21
  • 打赏
  • 举报
回复
哈哈 谢谢,你真热心
cblcz 2010-06-21
  • 打赏
  • 举报
回复
LZ还没解决?
帮顶了
name61 2010-06-21
  • 打赏
  • 举报
回复
只有加分了。。
name61 2010-06-21
  • 打赏
  • 举报
回复
哈哈 问题终于解决了,我是在codeproject找老外帮忙的,原来是我不仔细观察代码的缘故,谢谢么么啊
修改后的代码时这样的:

DECLARE_APP(MyApp)
IMPLIMENT_APP(MyApp)

bool MyApp::OnInit()//问题就出在这儿 编译后的提示是:

将IMPLIMENT_APP(MyApp)改为 IMPLEMENT_APP(MyApp)就可以了
原来编译提示说的是前面的构造函数或析构函数有问题

name61 2010-06-19
  • 打赏
  • 举报
回复
自己顶一下,待解决中。。。
ForestDB 2010-06-18
  • 打赏
  • 举报
回复
帮顶。
name61 2010-06-18
  • 打赏
  • 举报
回复
大清早的,发现老邓依然没有出现,早晨的希望破碎了
shiweifu 2010-06-18
  • 打赏
  • 举报
回复
后者的代码没有
DECLARE_APP
shiweifu 2010-06-18
  • 打赏
  • 举报
回复
觉得wxWidgets的代码一目了然,给的例子也很全面
比MFC风格上好不少
name61 2010-06-17
  • 打赏
  • 举报
回复
我杯具,你的代码可行,但是我的还是老问题,实在想不通是哪里出问题了
cblcz 2010-06-17
  • 打赏
  • 举报
回复

#include <wx/wx.h>
class Simple : public wxFrame
{
public:
Simple(const wxString& title);

};

Simple::Simple(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(250, 150))
{
Centre();
}

class MyApp : public wxApp
{
public:
virtual bool OnInit();
};

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
Simple *simple = new Simple(wxT("Simple"));
simple->Show(true);

return true;
}


这个代码简单一点,编译试试呢,如果出错,则是你配置的问题了
cblcz 2010-06-17
  • 打赏
  • 举报
回复
代码是没问题的,坐等老邓

(看到wxwidgets就想到老邓了...)
name61 2010-06-17
  • 打赏
  • 举报
回复
附上代码的后半截:

{
SetIcon(wxIcon(mondrian_xpm));

wxMenu *fileMenu = new wxMenu;
wxMenu *helpMenu = new wxMenu;
helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"),
wxT("Show about dailog"));
fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt-X"),
wxT("Quit this program"));

wxMenuBar * MenuBar = new wxMenuBar();
MenuBar->Append(fileMenu, wxT("&File"));
MenuBar->Append(helpMenu, wxT("&Help"));

SetMenuBar(MenuBar);

CreateStatusBar(2);
SetStatusText(wxT("Welcome to wxWidgets!"));
}

name61 2010-06-17
  • 打赏
  • 举报
回复
路径方面没问题,我标注的那里是唯一的问题
cblcz 2010-06-17
  • 打赏
  • 举报
回复
这是书上的代码吧,代码是没错的,看看路径配置呢

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧