gpt4 book ai didi

c++ - 链接从 wxDialog 继承的类时出错

转载 作者:行者123 更新时间:2023-11-28 00:53:01 27 4
gpt4 key购买 nike

我写了一个继承自wxDialog的类。我目前在 Ubuntu 12.04 上,使用 Code::Blocks 和 gcc 4.6。在我将此类包含在项目中之前,我的应用程序工作正常:调试和发布配置给出相同的错误。这是代码:

头文件

#ifndef EBCDIALOG_H
#define EBCDIALOG_H

#include <wx/dialog.h>
#include <wx/sizer.h>
#include <wx/textctrl.h>
#include <wx/button.h>

class EBCDialog : public wxDialog
{
public:

EBCDialog(wxWindow* parent, wxWindowID id, const wxString& title );
~EBCDialog();

void OnOK(wxCommandEvent& event);
private:

DECLARE_CLASS(EBCDialog)
DECLARE_EVENT_TABLE()
};

#endif //EBCDIALOG_H

Cpp文件:

#include "EBCDialog.h"

EBCDialog::EBCDialog(wxWindow* parent, wxWindowID id, const wxString& title ) : wxDialog(parent, id, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
// Create text ctrl with minimal size 100x60
topSizer->Add(new wxTextCtrl(this, wxID_ANY, wxT("test"), wxDefaultPosition, wxSize(100,60)),
1, // make vertically stretchable
wxEXPAND| // make horizontally stretchable
wxALL, // and make border all around
10); // set border width to 10

wxBoxSizer* buttonSizer = new wxBoxSizer( wxHORIZONTAL );
buttonSizer->Add(new wxButton(this, wxID_OK, _T("OK")),
0, // make horizontally unstretchable
wxALL, // make border all around: implicit top alignment
10); // set border width to 10

buttonSizer->Add(new wxButton(this, wxID_CANCEL, _T("Cancel")),
0, // make horizontally unstretchable
wxALL, // make border all around (implicit top alignment)
10); // set border width to 10

topSizer->Add(buttonSizer,
0, // make vertically unstretchable
wxALIGN_CENTER ); // no border and centre horizontally

SetSizer( topSizer ); // use the sizer for layout
topSizer->Fit( this );

// fit the dialog to the contents
topSizer->SetSizeHints( this ); // set hints to honor min size
}

EBCDialog::~EBCDialog()
{

}

void EBCDialog::OnOK(wxCommandEvent& event)
{

}

BEGIN_EVENT_TABLE(EBCDialog, wxDialog)
EVT_BUTTON(wxID_OK, EBCDialog::OnOK)
END_EVENT_TABLE()

这是代码:: block 日志:

g++ -Wall -I/usr/lib/i386-linux-gnu/wx/include/gtk2-unicode-debug-2.8 -I/usr/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D_WXDEBUG_ -D_WXGTK_ -pthread -O2 -I"/home/angelo/CodeBlocks/Event Bus Configurer/include" -I"/home/angelo/CodeBlocks/Event Bus Configurer/bitmaps" -c "/home/angelo/CodeBlocks/Event Bus Configurer/src/EBCDialog.cpp" -o obj/src/EBCDialog.o g++ -o "bin/Event Bus Configurer" obj/src/EBCApp.o obj/src/EBCDialog.o obj/src/EBCFrame.o obj/src/EBCList.o obj/src/HandlerFile.o -L/usr/lib/i386-linux-gnu -pthread -Wl,-Bsymbolic-functions -Wl,-z,relro -L/usr/lib/i386-linux-gnu -lwx_gtk2ud_richtext-2.8 -lwx_gtk2ud_aui-2.8 -lwx_gtk2ud_xrc-2.8 -lwx_gtk2ud_qa-2.8 -lwx_gtk2ud_html-2.8 -lwx_gtk2ud_adv-2.8 -lwx_gtk2ud_core-2.8 -lwx_baseud_xml-2.8 -lwx_baseud_net-2.8 -lwx_baseud-2.8 -s obj/src/EBCDialog.o:(.rodata._ZTV9EBCDialog[vtable for EBCDialog]+0x8): undefined reference to `EBCDialog::GetClassInfo() const' collect2: ld returned 1 exit status Process terminated with status 1 (0 minutes, 2 seconds) 1 errors, 0 warnings

感谢任何帮助,谢谢!

最佳答案

从您的代码中删除 DECLARE_CLASS(EBCDialog),基类 wxDialog 已经为您完成了。

来自documentation :

wxWidgets uses its own RTTI ("run-time type identification") system which predates the current standard C++ RTTI and so is kept for backwards compatibility reasons but also because it allows some things which the standard RTTI doesn't directly support (such as creating a class from its name).

The standard C++ RTTI can be used in the user code without any problems and in general you shouldn't need to use the functions and the macros in this section unless you are thinking of modifying or adding any wxWidgets classes.

关于c++ - 链接从 wxDialog 继承的类时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13035285/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com