-1

So I have a game I'm working on with the AGK library, and I have two classes that are affiliated with the problem at hand: oPlayer, and GlobalClass. oPlayer is a child of Framework and GlobalClass is merely a global-scope class used to store everything in the game. The error occurs when I compile it, VS 2013 doesn't complain about it. Here are the errors The errors as in VS2013

First off, sorry for all the code, I just have absolutley no idea what could be causing this.

So the files in question are

oPlayer.h

#pragma once
//This is the player's class, actual code in oPlayer.cpp
#include "Constants.h"
#include "Framework.h"
#include "template.h"
#include "GlobalClass.h"

// Author: Paolo Mazzon
// Date Last Edited: 2015-08-01
// Name: oPlayer.h
// Purpose: To define the player class -- But not set the functions
// 
// Extra notes: None

class oPlayer : public Framework
{
public:
    Real hsp;
    Real vsp;
    Real speed;

    void playerInit(Real X, Real Y, GlobalClass globalObject)
    {
        //Set the standard variables to a default value
        x = X;
        y = Y;
        angle = 0;
        xScale = 1;
        yScale = 1;
        spriteIndex = agk::CreateSprite(unsigned int(globalObject.playerImage));
    }
};

And GlobalClass.h

#pragma once    
#include "template.h"
#include "Constants.h"
#include "Framework.h"
#include "oPlayer.h"
#include <list>

// Author: Paolo Mazzon
// Date Last Edited: 2015-08-01
// Name: GlobalClass.h
// Purpose: The class to hold variables that will be used everywhere
// 
// Extra notes: None

using namespace std;

//This is the class where everything will be stored
class GlobalClass
{
public:
    //Sprites
    Integer playerImage;

    //All of the objects
    list<Framework> gameObjects;

    GlobalClass()
    {
        //Load player image
        playerImage = agk::LoadImage("SprPlayer.png");
    }

    //This is used to add objects to the game
    Integer objectCreate(Framework object)
    {
        //Append it to gameObjects
        gameObjects.insert(gameObjects.end(), object);
    }
};

And last, the portion of main in which this is called.

//Needed practically everywhere
GlobalClass global;

void app::Begin(void)
{
    agk::SetVirtualResolution (960, 540);
    agk::SetClearColor( 151,170,204 );
    agk::SetSyncRate(60,0);
    agk::SetScissor(0,0,0,0);

    //Load in some of them objects m8
    oPlayer ObjPlayer;
    ObjPlayer.playerInit(0, 0, global);
    global.objectCreate(ObjPlayer);
}

As I said, I am using the AGK libraries to develop the game, so that's what app:Begin is, it's just the first thing called when the game starts.

Any help is greatly appreciated.

null
  • 548
  • 2
  • 6
  • 17

1 Answers1

1

Each error code has a documentation page of its own (or at least it should have). The page for C2061 starts by saying

The compiler found an identifier where it wasn't expected. Make sure that identifier is declared before you use it.

The error is happening at line 22 in oPlayer.h. Assuming I've counted correctly, that line looks like this...

void playerInit(Real X, Real Y, GlobalClass globalObject)

The error also indicates that the identifier in question is GlobalClass. Thus it would appear that playerInit is being declared before GlobalClass has been declared.

It's only a guess but I suspect that whatever .cpp file is being compiled has an #include of GlobalClass.h. That in turn will #include oPlayer.h which will try to #include GlobalClass.h a second time. However the #pragma once at the start of GlobalClass.h will keep that second include from having any effect.

The compiler will move on to the declaration of the oPlayer class and the playerinit method. At this point we're at line 5 of GlobalPlayer.h - well before the declaration of the GlobalClass class - and at line 22 of oPlayer.h so the identifier GlobalClass is undefined.

Frank Boyne
  • 4,400
  • 23
  • 30
  • Thanks! I guess I completely overlooked that problem. Also, I didn't know all there error codes were in the manual, so thanks for telling me! – null Aug 02 '15 at 19:56