Make class inherit from other class

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Wanderer82
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 675
Joined: Tue Jul 26, 2016 2:00 pm

Make class inherit from other class

Post by Wanderer82 »

Hi

I'm trying to make the class "RunningText" a derived class from the class "Object". But somehow my code is wrong, I get different errors when I try different solutions. For example:
RunningText.cpp|9|error: expected identifier before 'public'|
RunningText.cpp|9|error: no matching function for call to 'Object::Object()'|
So my class files are:

RunningText.h

Code: Select all

#include "wx/wx.h"
#include "RunningText.h"
#include "PageLayout.h"
#include "Object.h"

class PageLayout;
class Object;

RunningText::RunningText(wxWindow *parent, wxWindowID id, wxString m_runningText, wxFont &staticTextFont, wxFont &comboBoxFont, PageLayout &Layout) : public Object
{
Object.h

Code: Select all

#ifndef OBJECT_H
#define OBJECT_H

#include "wx/wx.h"
#include "Birkly_GUIMain.h"

class PageLayout;

class Object : public wxPanel
{
    public:
        Object(wxWindow *parent, wxWindowID id, wxString m_runningText, wxFont &staticTextFont, wxFont &comboBoxFont, PageLayout &Layout);

    protected:

    private:

};

typedef std::vector<Object *> ObjectList;

#endif // OBJECT_H
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Make class inherit from other class

Post by doublemax »

Code: Select all

RunningText::RunningText(wxWindow *parent, wxWindowID id, wxString m_runningText, wxFont &staticTextFont, wxFont &comboBoxFont, PageLayout &Layout) : public Object
As Object has no default constructor, you must pass all needed parameters to its constructor in that line.
Use the source, Luke!
Wanderer82
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 675
Joined: Tue Jul 26, 2016 2:00 pm

Re: Make class inherit from other class

Post by Wanderer82 »

You mean, I have to pass values / variables or just the same paramters as Object has? Because this won't work:

Code: Select all

RunningText::RunningText(wxWindow *parent, wxWindowID id, wxString m_runningText, wxFont &staticTextFont, wxFont &comboBoxFont, PageLayout &Layout) : public Object(wxWindow *parent, wxWindowID id, wxString m_runningText, wxFont &staticTextFont, wxFont &comboBoxFont, PageLayout &Layout)
I see that it's the first time I'm trying to use a derived class :lol:
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Make class inherit from other class

Post by ONEEYEMAN »

Hi,
What is this class purpose? In other words - are you sure you need wxObject and not something else?

Thank you.
Wanderer82
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 675
Joined: Tue Jul 26, 2016 2:00 pm

Re: Make class inherit from other class

Post by Wanderer82 »

It's not wxObject, it's Object. "Object" is my own class and has nothing to do with any wxWidgets object. But maybe I misunderstand you. Did you call it wxObject because it's derived from wxPanel?

Well actually it's like this: I have a vector which stores objects (wxPanels). A "RunningText" is such an object, but there will be others like "Headline" or "DialogText" which differ a bit in their design. I don't want to write all that code for each object inside one class, so I thought it would be better to have like a "master class" called "Object" and then have these subclasses. Like this I won't have differently named objects (like RunningText or DialogText etc.) but only one that I can put inside an "ObjectList" vector. So maybe I need different constructors for my object with different parameters. But then I'll still have other classes for these subclasses with different header and .cpp files. I'm still in the process of designing my app and just "fiddling around" what might be the best way.

Thinking about it more, I don't actually really know what I want to do. Or at least I guess it won't work with derived classes. Somehow I thought I could like create an "Object" and pass a parameter that says what kind of object it has to be (RunningText, DialogText etc.). So in the end on the outside I'd only have an "Object" but inside it's something more specific. Or do I have to declare the derived classes directly inside the Object header file and can then create a separate .cpp file for these classes where I put the specific code?
Post Reply