为什么我得到“不是类或命名空间"?错误 [英] Why am I getting "is not a class or namespace" error
问题描述
我有一个产生错误的文件
I have a file that is generating the error
"Block" is not a class or a namespace name
上线
typedef Block::point point;
但是,我确信这是一个我已经创建并#included 在下面的文件中的类
However, I'm positive that it's a class that I've both created and #included in the file below
'texture.h'.
'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 文件.
Also just for good measure, here is the block.h file in question.
#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;
};
我不知道为什么我会为肯定存在的类收到此错误.提前致谢.
I have no idea as to why i could be getting this error for a class that certainly exists. Thanks in advance.
推荐答案
我看到循环包含: Block.h
包含 Texture.h
,其中包含 Block.h
.
I see cyclic includes : Block.h
includes Texture.h
which includes Block.h
.
在这个网站上搜索循环头依赖",你会看到很多关于这个的主题,在那里你可以找到如何解决这个难题的解决方案,最常见的是使用前向声明成员数据的类和指针声明.类的前向声明可帮助您避免包含标题,数据的指针声明可帮助您定义封闭类.这只是一个提示,现在搜索上述主题以获得详细答案.
Search for "cyclic header dependency" on this site, you will see many topics on this, where you can find solution as to how to solve this puzzle, the most common being using forward declarations of classes and pointers declarations of member data. Forward declarations of classes helps you avoid including headers, and pointers declarations of data helps you defining the enclosing class. That is a just a hint, now search for aforementioned topics for detailed answers.
这篇关于为什么我得到“不是类或命名空间"?错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!