简体   繁体   English

C++ 类名不命名类型

[英]C++ class name does not name a type

#ifndef MAIN_H_INCLUDED
#define MAIN_H_INCLUDED
#include "Setup.h"
#include "mainCharacter.h"

class Main {

public:
    Main(int pScreenWidth, int pScreenHeight);
    ~Main();

void gameLoop();

private:
    bool quit;
    Setup* setup;

    mainCharacter* tom;

    int screenWidth;
    int screenHeight;

    int mouseX;
    int mouseY;
};
#endif // MAIN_H_INCLUDED

I saw the other topics on this, but the error im getting is not of the same type, how can it tell me that我看到了关于此的其他主题,但我得到的错误类型不同,它怎么能告诉我

Setup* setup;
mainCharacter* tom;

does not name a type when the includes are above ?当包含在上面时不命名类型? im using code::blocks if that matters.如果这很重要,我正在使用 code::blocks。

EDIT://////////////////////编辑://////////////////////

This is the Setup header:这是设置标题:

#ifndef SETUP_H_INCLUDED
#define SETUP_H_INCLUDED

#include <SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>

#include "Main.h"
#include "Sprite.h"

class Setup {

public:
    Setup(int screenWidth, int screenHeight);
    ~Setup();

    SDL_Renderer* getRenderer();
    SDL_Event* getEvent();

private:
    SDL_Window* window;
    SDL_Renderer* renderer;
    SDL_Event* event;
};

#endif // SETUP_H_INCLUDED

and this is the mainCharacter header:这是 mainCharacter 标头:

#ifndef MAINCHARACTER_H_INCLUDED
#define MAINCHARACTER_H_INCLUDED

#include "Sprite.h"
#include "Setup.h"
#include <cmath>

class mainCharacter {

public:
    mainCharacter(Setup* pSetup, int* pMouseX, int* pMouseY);
    ~mainCharacter();

    double getDistance(int x1, int y1, int x2, int y2);

    void update();
    void draw();

private:
    Sprite* shagy;

    ///some variables are here/////

    Setup* setup;
};

#endif // MAINCHARACTER_H_INCLUDED

there are Setup.cpp and mainCharacter.cpp files and they got a long code written on them, the only thing i inclue in setup.cpp is setup.h and maincharacter.cpp i only include maincharacter.h有 Setup.cpp 和 mainCharacter.cpp 文件,它们上面写了很长的代码,我在 setup.cpp 中唯一包含的是 setup.h 和 maincharacter.cpp 我只包含 maincharacter.h

#ifndef SETUP_H_INCLUDED
#define SETUP_H_INCLUDED

Make sure you aren't defining SETUP_H_INCLUDED somewhere else, this is the only reason i see.确保您没有SETUP_H_INCLUDED其他地方定义SETUP_H_INCLUDED ,这是我看到的唯一原因。

Also it's possible that your %INCLUDE% (include directories) has another Setup.h somewhere, which does not define Setup class, and your Setup.h is not loaded.此外,您的 %INCLUDE%(包括目录) Setup.h某处有另一个Setup.h ,它没有定义Setup类,并且您的Setup.h未加载。

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

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