-1

I'm using wxWidgets with CodeBlocks, and I'm trying to instantiate a class called FileManager as an attribute of the Frame for wxWidgets, and pass the wxFrame parent to the constructor of FileManager. The objective is to be able to able to refer to the wxFrame from within FileManager. I'm getting an error "FileManager does not name a type". Not sure what I'm doing wrong thanks

The project is called "MullSimple_CB" so the main frame class is "Mull_Simple_CBFrame" Here are the files. So the main object is a wxFrame object of class MullSimple_CBFrame, defined inside MullSimple_CBMain. The class I want instantiated as a member of that class is FileManager

MullSimple_CBMain.h

#ifndef MULLSIMPLE_CBMAIN_H
#define MULLSIMPLE_CBMAIN_H

#include "non-wx/file_manager.h"

class MullSimple_CBFrame: public wxFrame
{
    public:

        MullSimple_CBFrame(wxWindow* parent,wxWindowID id = -1);
        virtual ~MullSimple_CBFrame();


        // ERROR ON THIS LINE:
        // "'FileManager' does not name a type"
        FileManager fileManager(MullSimple_CBFrame parentFrame);

    private

        DECLARE_EVENT_TABLE()
};

#endif // MULLSIMPLE_CBMAIN_H

MullSimple_CBMain.cpp

#include "wx_pch.h"
#include "MullSimple_CBMain.h"
#include <wx/msgdlg.h>

#include "non-wx/file_manager.h"


MullSimple_CBFrame::MullSimple_CBFrame(wxWindow* parent,wxWindowID id)
{

    FileManager fileManager(this);

}

FileManager.h

#ifndef FILE_MANAGER_H_INCLUDED
#define FILE_MANAGER_H_INCLUDED

#include "../MullSimple_CBMain.h"

class FileManager
{
    private:

        MullSimple_CBFrame storeMainFrame;

    public:

        // constructor
        FileManager(MullSimple_CBFrame mainFrame);

};

#endif // FILE_MANAGER_H_INCLUDED

FileManager.cpp

#include "file_manager.h"
#include "../MullSimple_CBMain.h"

FileManager::FileManager(MullSimple_CBFrame mainFrame): storeMainFrame(mainFrame))
{

}
Geoff L
  • 765
  • 5
  • 22
  • Does this answer your question? [Resolve build errors due to circular dependency amongst classes](https://stackoverflow.com/questions/625799/resolve-build-errors-due-to-circular-dependency-amongst-classes) – Asteroids With Wings Aug 09 '20 at 19:12

1 Answers1

0

Your file_manager.h file includes MullSimple_CBMain.h and the MullSimple_CBMain.h file includes your file_manager.h.

You end up with a never ending chain of includes... which never resolve.

Consider putting forward declarations into a single .h file and then have your .h files only include it as opposed to including the individual class.h files themselves. The only time you need to include the class.h files themselves is if you need the compiler to know about the full definition of the class as opposed to just knowing the class exists at all.

DynasticSponge
  • 1,416
  • 2
  • 9
  • 13