为什么我会收到“不是一个类或命名空间”错误(Why am I getting “is not a c

2019-07-05 05:19发布

我有一个生成该错误的文件

"Block" is not a class or a namespace name

在线上

typedef Block::point point;

不过,我敢肯定,这就是我一直都创建并执行#included下面的文件类

'texture.h'。

    #pragma once
#include "Block.h"
#include <iostream>
#include <vector>
#include <GL/glut.h>
#include "lodepng.h"

using namespace std;
typedef Block::point point;


class Texture
{



public:
    Texture(int width, int height, string filename);//initialises our texture and loads its pixeldata into a buffer
    Texture(void);
    ~Texture(void);

    void draw(point centerPoint, point dimensions);

    unsigned int w;//width of our imagefile
    unsigned int h;

    GLuint texID;//the ID we will give OGL for this particular texture.

private:
    vector<unsigned char> image;
    void texGLInit();
};

也只是良好的措施,这里是有问题的block.h文件。

#pragma once
#include <GL/glut.h> 
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "Texture.h"

class Block
{


public:
    struct point
    {
        GLfloat x, y;
    };

    enum State  {STATIC, FALLING, SELECTED};

    enum Colour {RED, BLUE, PURPLE, GREEN, YELLOW, DEAD};

    Block(void);
    ~Block(void);

    Block(int gridPosX, int gridPosY, point offset);
    point gridPos;//the blocks designated position in the 8x8 array
    point centerPos;//the blocks coordinates for the actual purpose of drawing

    State blockState;//the state of the block
    Colour blockColour;//the colour of the block

    void move();//checks whether the block is in a falling state and moves it appropriately
    void drawBlock();//no need to include the drawing coords as parameters. the block knows where it should be. The grid will simply tell it to draw itself.

private:
    void fall();//decrements the blocks position
    void assignRandomColour();//assigns a random colour to the block dependant upon its' texture
    void generateWorldPos();//gets our block a center position, for us to later to use to draw it.
    //the above function will also inherently define the size of each cell in the grid. I'm thinking each
    //cell should be 40x40. So each cell will be offset initially by 20px by 20px. 



    point gridOffset;



};

我不知道,为什么我可以得到这个错误对于确实存在的类。 提前致谢。

Answer 1:

我看到的循环包括: Block.h包括Texture.h包括Block.h

搜索“环头依赖症”在这个网站,你会,最常见的是使用正向类和成员数据的指针声明声明看到这一点,在那里你可以找到解决方案,如何解决这个难题很多话题。 类的前置声明可以帮助你避免包括头和数据的指针声明可以帮助你定义封装类。 这是只是一个提示,现在要查找的详细解答上述主题。



文章来源: Why am I getting “is not a class or namespace” error
标签: c++ scope