Forwarded class, can't access to method

70 views Asked by At

I'm trying to access a method of my parent class, see the code:

#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);

As you can see it's a wxWidgets project. After I forwarded the class, I want to access a method of my class, but I get this error about using an invalid type..any ideas?

1

There are 1 answers

0
juanchopanza On BEST ANSWER

After I forwarded the class, I want to access a method of my class, but I get this error about using an invalid type..any ideas?

To instantiate or invoke any methods of a class you need the definition. A forward declaration only states that there's a type with a given name.

You may be able to fix this by putting code that needs full definitions (e.g. wxMenu *CreatePopupMenu ()) in implementation files.