'Input' 不会命名类型错误。不知道为什么?

'Input' does not name a type error. Can't figure out why?

本文关键字:不知道 错误 为什么 Input 类型      更新时间:2023-10-16

当我编译时,我得到错误:'Input'没有在第17行命名类型

#ifndef GAME_H
#define GAME_H
#include "input.h"
// Can forward declare "class Input(GLFWwindow*);" here but it still
//     gives the same error.
class Game
{
    public:
        Game(Input* input);
        ~Game();
        void Input();
        void Update();
        void Render();
    private:
        Input* mpInput; //error here.
};
#endif // GAME_H

Input.h是这样的

#ifndef INPUT_H
#define INPUT_H
#include <GLFW/glfw3.h>
#include <vector>
class Input
{
    public:
        Input(GLFWwindow* window);
        ~Input();
        bool GetKey(int keyCode);
        bool GetKeyDown(int keyCode);
        bool GetKeyUp(int keyCode);
        void Update();
    private:
        GLFWwindow* mpWindow;
        std::vector<bool> mCurrentKeys;
        std::vector<bool> mDownKeys;
        std::vector<bool> mUpKeys;
        const int NUM_KEYCODES = 256;
};
#endif // INPUT_H

我不知道这里发生了什么。我昨天遇到了类似的问题,无法解决,所以我尝试保存项目,关闭Code::Blocks,重新启动Code::Blocks,然后重新打开项目。然后我编译了它,它没有明显的原因就工作了。没有更改代码或其他内容。我试着在这里重新加载项目,但它仍然给出相同的错误。

在类代码中有方法Input。混合方法和类型的名称通常不是一个好主意。在您的一个类Game方法中考虑以下代码:

Input();

这是一个方法Input调用或您正在尝试创建Input类实例?试着重命名你的Input方法

相关文章: