0

I'm getting the following error when compiling, using GCC 11.2.0:

/src/SearchController.h:12:23: error: ‘HelpModel’ was not declared in this scope
   12 |         std::optional<HelpModel> searchModel;
      |                       ^~~~~~~~~
/src/SearchController.h:12:32: error: template argument 1 is invalid
   12 |         std::optional<HelpModel> searchModel;
      |                                ^

I'm including the HelpModel class in the header, but this is pretty much my first C++ program so my understanding of this is pretty thin at the min.

Here's the SearchControlle.h file

#ifndef ARCH_HELP_SEARCH_CONTROLLER
#define ARCH_HELP_SEARCH_CONTROLLER

#include <string>
#include <optional>

#include "HelpModel.h"

class SearchController
{
    public:
        std::optional<HelpModel> searchModel;
        void searchedFor(std::string searchTerm);
};

#endif

And here's the HelpModel.h file:

#ifndef ARCH_HELP_HELP_MODEL
#define ARCH_HELP_HELP_MODEL

#include <vector>
#include "Topic.h"
#include "TerminalView.h"

class HelpModel 
{
    public:
        HelpModel(TerminalView view);

    private:
        TerminalView view;
        std::vector<Topic> topics;
        void getTopics();
        void pushToView();
};

#endif

Here's TerminalView.h

#ifndef ARCH_HELP_TERMINAL_VIEW
#define ARCH_HELP_TERMINAL_VIEW

#include <vector>
#include <string>
#include "SearchController.h"
#include "Topic.h"

class TerminalView
{
    public:
        void makeHeader();
        void update(std::vector<Topic> modelData);
    
    private:
        std::string searchTerm;
        std::vector<Topic> helpData;
        SearchController controller;
        void makeSearchInput();
        void printToTerminal();
        void printAnswers(std::vector<std::string> answers);
};

#endif

What I would like to be able to do is then assign an instance of HelpModel to the SearchController like so - say in main.cpp:

HelpModel model(terminal);
SearchController controller;
controller.searcModel = model;

Any advice greatly appreciated

Mr Eeeeee
  • 1
  • 1
  • Do `Topic.h` or `TerminalView.h` directly or indirectly include `SearchControlle.h` ? – Richard Critten Mar 06 '22 at 21:36
  • 2
    Your probably have circular includes. You are not showing all of them, so we cannot verify that. – user17732522 Mar 06 '22 at 21:36
  • Hi, thanks for getting back to me, and yes TerminalView.h does indeed contain a reference to SearchController.h - I've updated the question to show that code as well hope that helps? So the compiler is actually telling me there is likely circular dependencies? – Mr Eeeeee Mar 06 '22 at 22:06

0 Answers0