-1
我試圖訪問我的父類的方法,請參見代碼:轉發類,不能訪問方法
#include <wx/wx.h>
#include <wx/taskbar.h>
#include <iostream>
#include "appicon.xpm"
class MyFrame; // forward
class mywxTaskBarIcon : public wxTaskBarIcon
{
private:
MyFrame *m_parent;
public:
mywxTaskBarIcon (MyFrame *parent, const wxIcon& icon) :
wxTaskBarIcon(), m_parent (parent)
{
SetIcon (icon, wxT("Listos"));
}
virtual ~mywxTaskBarIcon() {
std::cout << "died" << std::endl;
}
protected:
virtual wxMenu *CreatePopupMenu() {
return m_parent->getFileMenu(); // invalid type
}
};
class MyFrame : public wxFrame
{
private:
wxIcon main_icon;
wxSharedPtr<mywxTaskBarIcon> tray;
public:
MyFrame (const wxString& title) :
wxFrame (NULL, wxID_ANY, title), main_icon(appicon)
{
SetIcon (main_icon);
wxMenuBar *menubar = new wxMenuBar;
menubar->Append (loadFile(), wxT("&Aplicación"));
SetMenuBar(menubar);
tray = wxSharedPtr<mywxTaskBarIcon>(new mywxTaskBarIcon (this, main_icon));
Centre();
Show();
}
wxMenu * getFileMenu() {
return loadFile();
}
protected:
wxMenu* loadFile() {
wxMenu *file = new wxMenu;
file->Append (wxID_EXIT, wxT("&Salir"));
return file;
}
};
class MyApp : public wxApp
{
public:
virtual bool OnInit() {
new MyFrame (wxT("Hola"));
return true;
}
};
wxIMPLEMENT_APP (MyApp);
wxDECLARE_APP (MyApp);
正如你可以看到這是一個wxWidgets的項目。在我轉發了這個類之後,我想訪問我的類的一個方法,但是我得到了關於使用無效類型的錯誤。
請參閱[在C++中解析循環依賴項](http://stackoverflow.com/questions/625799/resolve-circular-dependencies-in-c) – juanchopanza