【问题标题】:'Input' does not name a type error. Can't figure out why?“输入”没有命名类型错误。想不通为什么?
【发布时间】:2015-07-11 05:05:05
【问题描述】:

编译时出现错误:'Input' does not name a type on line 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,然后重新打开项目。然后我编译了它,它没有明显的原因起作用。没有更改任何代码或任何东西。我也尝试在这里重新加载项目,但它仍然给出同样的错误。

【问题讨论】:

    标签: c++ gcc compiler-errors codeblocks


    【解决方案1】:

    您的课程代码中有Input 方法。混合方法和类型的名称通常是一个坏主意。在您的课程Game 方法之一中考虑此代码:

    Input();
    

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

    【讨论】:

    • 是的!谢谢!可能我需要很长时间才能注意到这一点,并认为这可能是问题所在!
    猜你喜欢
    • 2011-07-28
    • 2011-12-10
    • 2013-09-09
    • 2015-12-01
    • 2014-12-16
    • 2016-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多