Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6234133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:25:43+00:00 2026-05-24T10:25:43+00:00

So I’m trying to get class Herder to inherit from class Mob. But I

  • 0

So I’m trying to get class “Herder” to inherit from class “Mob”. But I am getting compiler errors that read as follows:

error: invalid use of incomplete type 'struct Mob'
error: forward declaration of 'struct Mob'

This is what Herder.h looks like:

#ifndef HERDER_H_INCLUDED
#define HERDER_H_INCLUDED

#include <SFML/Graphics.hpp>
#include <cstdlib>
#include "Level.h"
#include "Mob.h"

class Mob;

class Herder : public Mob
{
public:
    //Member functions.
    Herder(Level* level, int x, int y);
    void virtual GameCycle(sf::RenderWindow* App);
    void virtual Die();
    void Roar();
protected:
    float m_RoarCountdown;
    float m_RoarTime;
    float m_Speed;
    bool m_Roaring;
};

#endif // HERDER_H_INCLUDED

Figuring that it must be the class Mob; that is causing this, I remove it, but then I get the following error, refering to the line where the curly braces open:

error: expected class-name before '{' token

This is actually why I originally added the forward declaration – I had thought that the compiler wasn’t recognizing Mob in class Herder : public Mob, so I figured I would forward declare.

I don’t think it’s a case of cyclical dependency, as has been the case in some cases I found via Google – “Mob.h” contains nothing to do with the Herder class whatsoever.

I have tried removing #include "Mob.h" altogether and sticking with just the forward declaration, but that doesn’t work either – I get only one error, again:

error: invalid use of incomplete type 'struct Mob'

This is confusing. I’ve successfully gotten classes to inherit before, and this code seems analogous in all relevant ways to my previous successful attempts.


EDIT: Here are the contents of Mob.h

#ifndef MOB_H_INCLUDED
#define MOB_H_INCLUDED

#include <SFML/Graphics.hpp>
#include <cstdlib>
#include "Level.h"

class Level;

class Mob
{
public:
    //Member functions.
    Mob(Level* level, int x, int y);
    float GetX();
    float GetY();
    void SetColor(sf::Color color);
    void virtual GameCycle(sf::RenderWindow* App) = 0;
    void virtual Die() = 0;
    void Draw(sf::RenderWindow* App);
protected:
    float m_X;
    float m_Y;
    bool m_Moving;
    int m_Health;
    sf::Sprite m_Sprite;
    Level* pLevel;
};

#endif // MOB_H_INCLUDED

EDIT: Here are the contents of the “Level.h” file. Note that Baby is a child class of Mob in much the same way as Herder; both experience the same errors.

#ifndef LEVEL_H_INCLUDED
#define LEVEL_H_INCLUDED

#include <SFML/Graphics.hpp>
#include <cstdlib>
#include "Tile.h"
#include "Herder.h"
#include "Baby.h"

class Tile;
class Herder;
class Baby;

/// LEVEL
/// This is the collection of all data regarding a level, including layout, objects, mobs, and story elements.
///

class Level
{
public:
    //Constructor
    Level(int height, int width, std::string name);
    //For obtaining positional data
    int GetHeight();
    int GetWidth();
    std::string GetName();
    sf::Image GetTileImage(int image);
    sf::Image GetMobImage(int image);
    std::vector< std::vector<Tile> >& GetGrid();
    void NewHerder(int x, int y);
    void NewBaby(int x, int y);
    void GameCycle(sf::RenderWindow* App);
    void GraphicsCycle(sf::RenderWindow* App);
private:
    //Size
    int m_Height;
    int m_Width;
    //Spatial coords
    std::string m_Name;
    //The grid of tiles.
    std::vector< std::vector<Tile> > m_Grid;
    //A vector of the images to be used for tiles.
    std::vector<sf::Image> m_TileImages;
    //A vector of the images to be used for tiles.
    std::vector<sf::Image> m_MobImages;
    //The herders
    std::vector<Herder> m_Herders;
    //The babies
    std::vector<Baby> m_Babies;
};

#endif // LEVEL_H_INCLUDED

EDIT: Pre-emptively, here are the contents of Tile.h:

#ifndef TILE_H_INCLUDED
#define TILE_H_INCLUDED

#include <SFML/Graphics.hpp>
#include <cstdlib>
#include "Level.h"

class Level;

/// TILE
/// This is the basic environmental unit in the game
///

class Tile
{
public:
    //Constructor
    Tile(int col, int row, int size, int type, Level* level);
    //For obtaining positional data
    int GetX();
    int GetY();
    int GetRow();
    int GetCol();
    //For obtaining type data
    int GetType();
    //For obtaining string type data
    std::string GetStringType();
    //For changing type data
    void SetType(int type);
    void SetStringType(std::string character);
    //For activities that regularly take place
    void GameCycle();
    //Draws the tile.
    void Draw(sf::RenderWindow* App);
private:
    //The level this tile belongs to.
    Level* m_Level;
    //Size (it's a square!)
    int m_Size;
    //Spatial coords
    int m_X;
    int m_Y;
    //Grid coords
    int m_Row;
    int m_Col;
    //Type
    int m_Type;
    //Visual data
    sf::Sprite m_Tile;
};

#endif // TILE_H_INCLUDED
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:25:44+00:00Added an answer on May 24, 2026 at 10:25 am

    It is a cyclic dependency (Herder.h includes Level.h which includes Herder.h, etc.).

    In Herder.h, simply replace this :

    #include "Level.h"
    

    with :

    class Level;
    

    and do the same in Mob.h

    The general rule is to include as little header files as possible (ie. only the ones you need). If you can get by with a forward declaration eg., then use that rather than a full include.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.