簡體   English   中英

為什么我收到“不是類或命名空間”錯誤

[英]Why am I getting "is not a class or namespace" error

我有一個生成錯誤的文件

"Block" is not a class or a namespace name

在線上

typedef Block::point point;

但是,我確信這是一個我在下面的文件中創建並#included 的類

'紋理.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;



};

我不知道為什么我會為一個肯定存在的類收到這個錯誤。 提前致謝。

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

在這個站點上搜索“循環頭依賴” ,你會看到很多關於這個的主題,你可以在那里找到如何解決這個難題的解決方案,最常見的是使用類的前向聲明和成員數據的指針聲明。 類的前向聲明可幫助您避免包含標題,數據的指針聲明可幫助您定義封閉類。 這只是一個提示,現在搜索上述主題以獲得詳細答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM