1

I'm working on a project in which I'm implementing an interface using SFML. So... I've created one base class SortingAlgorithms, the subclasses that will inherit from the base class and the Interface class which contains the interface implementations.

The project was working before when I had one single header file, but now I've separated the classes in different header files.

So my problem is in the Algorithms.h file, where the virtual method Sort is.

After compilation I get those errors:

C2065 'Interface' undeclared identifier

C2923 'std::unique_ptr':'Interface' is not valid template for argument '_Ty'

unable to recover from previous error(s); stopping compilation

Algorithms.h :

#ifndef ALGORITHMS_H_INCLUDED
#define ALGORITHMS_H_INCLUDED


#include "Interface.h"
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <vector>


/* Base class from which the sorting algorithms will inherit (Polymorphic class) */
class SortingAlgorithms
{
protected:
    std::vector<sf::RectangleShape> sequence;
    sf::RenderWindow& window;
    int minimum, maximum;
    int elements;

public:
    SortingAlgorithms();

    // Class constructor which initializes a sequence
    SortingAlgorithms(int min, int max, int els, sf::RenderWindow& win);

    std::vector<sf::RectangleShape> GetSequence() const;

    // A pure virtual function for overriding 
    virtual void Sort(std::unique_ptr<Interface>& init) = 0;

    // A method for printing the sequence
    void Print(std::unique_ptr<Interface>& init);
};






#endif // ALGORITHMS_H_INCLUDED

Interface.h :

#ifndef INTERFACE_H_INCLUDED
#define INTERFACE_H_INCLUDED

#include "Algorithms.h"
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <vector>


/* The Button class will allow us to create a button (a shape with text) */
class Button
{
protected:
    sf::Text text;
    sf::RectangleShape button;
public:
    Button();
    Button(std::string txt, sf::Color txtColor, int txtSize, sf::Color shapeColor, sf::Vector2f shapeSize);

    // Positionate method will set the position on (x, y) axis
    void Positionate(sf::Vector2f size);

    // SetShapeColor, SetTextColor will set the shape colors
    void SetShapeColor(sf::Color color);

    void SetTextColor(sf::Color color);

    // SetFont will set the text font e.g. arial
    void SetFont(sf::Font& font);

    // DetectMouse when hoovering over the button
    bool DetectButton(sf::RenderWindow& window);

    // Returns the text from inside of a button 
    std::string GetButton() const;

    // Changes the string text and repositionate the text
    void SetButton(const std::string& str);

    // Draw draws the button on the screen
    void Draw(sf::RenderWindow& window);
};


/* Class Interface contains the functionlaties of the window */
class Interface
{
protected:
    sf::RenderWindow window;
    sf::Font font;
    sf::Text hint;
    
    /* I'll be using a container for our buttons since we'll have some more */
    Button clrScrB;
    Button generateSeqB;
    Button sortAlgB;
    Button resetConfigB;
    Button increaseMinB;
    Button increaseMaxB;
    Button outputMinB;
    Button outputMaxB;
    Button plusElsB;
    Button minusElsB;
    Button outputElsB;

    int inputMin = 0;
    int inputMax = 0;
    int inputEls = 0;
    
    std::string algorithmType;
    std::string selectedAlg;
    std::shared_ptr<SortingAlgorithms> generateSeq;

    std::vector<Button> menuButtons;
    std::vector<Button> configButtons;
    std::vector<Button> sortingAlgsButtons;
    std::vector<Button> pathAlgsButtons;

public:
    Interface();

    // Initializes the window within the main loop  
    void Init(std::unique_ptr<Interface>& init);

    void SortingAlgMenu(std::unique_ptr<Interface>& init);

    void PathAlgMenu(std::unique_ptr<Interface>& init);

    void ConfigBar(std::unique_ptr<Interface>& init);
};






#endif // INTERFACE_H_INCLUDED
HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
Daniel
  • 335
  • 1
  • 11
  • Follow your include guard macros. The problem should make itself evident if your head-preprocess `Interface.h` defining guards, then including `Algorithms.h`, which includes `Interface.h` (which becomes a no-op because its guards are already affixed). I.e. you have a circular include problem, which isn't entirely uncommon, and a worthy search term on this site. – WhozCraig Jul 12 '20 at 09:49
  • That's it! Thanks :D – Daniel Jul 12 '20 at 10:43

0 Answers0