繁体   English   中英

错误 C2061 语法错误标识符——我不知道我做错了什么

[英]Error C2061 Syntax Error Identifier -- I don't know what I'm doing wrong

所以我有一个正在使用 AGK 库开发的游戏,并且我有两个与手头问题相关的类: oPlayerGlobalClass oPlayerFramework的子级,而GlobalClass只是一个全局范围的类,用于存储游戏中的所有内容。 当我编译它时发生错误,VS 2013 没有抱怨它。 以下是错误VS2013 中的错误

首先,对不起所有的代码,我只是完全不知道是什么导致了这种情况。

所以有问题的文件是

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));
    }
};

和 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);
    }
};

最后,调用 this 的 main 部分。

//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);
}

正如我所说,我正在使用 AGK 库来开发游戏,所以app:Begin就是这样,它只是游戏开始时调用的第一件事。

任何帮助是极大的赞赏。

每个错误代码都有自己的文档页面(或者至少应该有)。 C2061的页面开头说

编译器发现了一个不期望的标识符。 确保在使用之前声明标识符。

错误发生在 oPlayer.h 的第 22 行。 假设我数对了,那条线看起来像这样......

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

该错误还表明有问题的标识符是GlobalClass 因此,它会出现playerInit在声明前GlobalClass已申报。

这只是一个猜测,但我怀疑正在编译的任何 .cpp 文件都有 GlobalClass.h 的#include 反过来, #include oPlayer.h 将尝试第二次#include GlobalClass.ha。 然而, GlobalClass.h 开头的#pragma once将阻止第二个包含产生任何影响。

编译器将继续声明oPlayer类和playerinit方法。 在这一点上,我们在 GlobalPlayer.h 的第 5 行——远在GlobalClass类的声明之前——以及在GlobalClass第 22 行,所以标识符GlobalClass是未定义的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM