0

When I execute this code, I get the following error: ‘Block’ does not name a type This is the code:

Block.h

#include "Area.h"
#ifndef Block_H
#define Block_H
#ifndef Cube_H
#include "Cube.h"
#endif
#ifndef nullptr
#define nullptr 0
#endif

class Block : public Area
{

    int ID;
    int BlockType;
    Cube *cube;
    Block()
    {
    ID=0;
    BlockType=0;
    cube=0;
    }
};
#endif

Cube.h

#include "Area.h"
#ifndef Cube_H
#define Cube_H
#ifndef Block_H
#include "Block.h"
#define Block_H
#endif
// put all your classes and other stuff here
class Cube : public Area
{
    Block *blocks[8]=nullptr;
    int ID;
};

#endif // end of MYHEADER_H

this code, for whatever reason, doesn't compile. I've cross checked it with other sources, and it still doesn't compile.

Thanks.

4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Arbus
0

On including cube.h and compiling block.h you would get "Type name expected" for block. The cube.h will be compiled first before the compilation of class block.

class Cube : public Area
{
    Block *blocks[8]=nullptr;
    int ID;
};

Only after that the class block gets compiled.

class Block : public Area
{
 
    int ID;
    int BlockType;
    Cube *cube;
    Block()
    {
    ID=0;
    BlockType=0;
    cube=0;
    }
};

If you include block.h then also it would say "cube does not name a type".
So you have to declare the classes accordingly.

Edited by Arbus: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.