0

I made sure that there is no circular dependency and that the header files are included in hopes of getting the compiler to understand everything but I was wrong

Edit1: ALso have header guards like pragma once

Edit 2: forgot to add in all the header files

I should focus more on providing clearly complete content

relevant files:

Spawner.hpp // the header file that defines the class

#pragma once

// code skipped

#include "weapon.hpp"
#include "movement.hpp"

class Spawner{
private:

int spawnGapTime;
int spawnGapSet;

// If you plan to spawn finite enemies, then use constructor
int spawnLimit = -1;

EnemyTemplate* enemyData;
Weapon* givenWeapon;
Movement* givenMovement;



int ticks;

public:

Spawner(Weapon*, Movement*, EnemyTemplate*, std::vector <int>);

void update();
void spawn_enemy();
void spawn_count();

~Spawner(){
    delete givenWeapon;
    delete givenMovement;
    delete enemyData;
};


};

SceneGame.hpp (some relevant code)

#pragma once

#include <SFML\Graphics.hpp>

#include "scene.hpp"
#include "game.hpp"
#include "entity.hpp"
#include "movement.hpp"
#include "weapon.hpp"
#include "player.hpp"
#include "collisionGrid.hpp"
#include "spawner.hpp"

// forward declare

class BulletTemplate;

class SceneGame : public Scene{
private:

// some code skipped

    std::vector <Spawner*> spawner_list; // the source of the problem

// more code skipped
};

SceneGame.cpp (only including the constructor for relevance)

#include "sceneGame.hpp"
#include "input.hpp"

SceneGame::SceneGame(Game* game){

    this->game = game; // need this to run the game.

    // code skipped


    // SKIP to spawner_list
    //

    std::vector<BulletTemplate*> player_weapon;

    // Typical 3-way gun
    player_weapon.push_back(new BulletTemplate("bulletPlayer", 1, 15, false, 0));
    player_weapon.push_back(new BulletTemplate("bulletPlayer", 1, 15, false, -15));
    player_weapon.push_back(new BulletTemplate("bulletPlayer", 1, 15, false, 15));

    // simple rapid fire


    bullet_Patterns.push_back(player_weapon);

    std::vector<BulletTemplate*> enemy_weapon;

    // 2 shot rapid
    enemy_weapon.push_back(new BulletTemplate("bulletEnemy", 1, 10, false, -5));
    enemy_weapon.push_back(new BulletTemplate("bulletEnemy", 1, 10, false, 5));

    bullet_Patterns.push_back(enemy_weapon);


    // initalize Movement

    std::vector<sf::Vector2f> waypoints = {
        sf::Vector2f(-100, 0),
        sf::Vector2f(-100, -100),
        sf::Vector2f(0, -100),
    };

    //Movement* enemy_movement = new Movement(sf::Vector2f(400, 400), waypoints);

    // 
    //

    ///*
    std::vector <int> spawnParams = { 60 };

    // This is where I use the variable that compiler complained
    // Initalize the spawner
    spawner_list.push_back(new Spawner(
        new Weapon(enemy_weapon, "sequence_enemy", 60, { 8 }),
        new Movement(sf::Vector2f(400, 400), waypoints),
        new EnemyTemplate(this, "enemySprite", 1, 2, false,
        sf::Vector2f(400, 400)), spawnParams));

    //*/

    // Skipping irrelevant code

}

Even when I understood the basics of declaration and definition, I am still stumped. Is there any way I can resolve this issue

JBRPG
  • 141
  • 1
  • 2
  • 10
  • What is the error and where does it occur? – James Adkison Apr 12 '15 at 02:44
  • 1
    Add [header guards](http://en.wikipedia.org/wiki/Include_guard) to your `.hpp` files. – quant Apr 12 '15 at 02:48
  • The header guards is not the problem since they are included in every one. as for the error, here is the following: Error C0625: 'Spawner' undeclared identifier // main error // and some irrelevant errors about vector stuff The error is found when delcaring the variable using a vector of Spawner* – JBRPG Apr 12 '15 at 02:58
  • 1
    In the code you posted `SceneGame.cpp` doesn't include `SceneGame.hpp`... If you seriously expect to get any _good help_ you need to produce an [MCVE](http://stackoverflow.com/help/mcve). – James Adkison Apr 12 '15 at 03:02
  • 1
    @JBRPG whenever you start writing code, start small, make sure it compiles, then extend. What you posted is a relatively large chuck that no one is going to take the effort to debug/see what's wrong. Try reducing your case to the minimum one possible (i.e., getting rid of unnecessary functions etc). – vsoftco Apr 12 '15 at 03:03
  • 1
    Did you `#include ` ? We can't help you without your diligent attention to making a good question. – Ben Voigt Apr 12 '15 at 03:23
  • @ Ben Voigt the has been included in scene.hpp – JBRPG Apr 12 '15 at 03:25

1 Answers1

0

I have had similar errors with capitalization:

#include "sceneGame.hpp"

vs.

#include "SceneGame.hpp"

The header guard has been provided, arguably, by #pragma once. This is a good idea to avoid circular dependencies. Some compilers support the #import directive, a guarded alternative to #include.

SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179