Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have 3 classes that have been created
Map class
#ifndef MAP_H
#define MAP_H

#include "position.h"
#include "Entity.h"
#include <iostream>
#include <windows.h>
#include <ctime>
#include <iostream>

class Map
{
private:
	char mapSize[21][21];
public:
	Map();
	~Map();
};
#endif


Entity class
#ifndef ENTITY_H
#define ENTITY_H

#include "Map.h"

class Entity
{
	position pos;
public:
	Entity();
	~Entity();
};
#endif


position class
#ifndef POSITION_H
#define POSITION_H

#include "Map.h"

class position
{
public:
	int x;
	int y;
	position();
	~position();
};

#endif


It seems that the source of the error is from entity.h, specifically the line
position pos;


These classes, when compiled together, gives me two errors
1) C4430 - missing type specifier - int assumed. Note: C++ does not support default-int
2) C3646 - 'pos': unknown override specifier

I would like to know what is causing the issue, as I can't seem to figure out what the issue it

What I have tried:

Originally, in entity.h I had included position.h as well, but i removed it thinking that map.h was causing the loop. Apparently not.

FYI:
position pos;

was defined in public before, but it still did not work
Posted
Updated 27-Nov-18 3:31am
v2
Comments
Rick York 27-Nov-18 10:38am    
KarstenK is correct but why are they including Map.h? There are no instances of a Map in either of those classes so they don't need to.

In entity header file you must include the position header to declare the position class for the entity class member.
 
Share this answer
 
Comments
Michael Haephrati 16-Jun-20 15:55pm    
Please elaborate and give an example
Without giving you the answer directly - think about what each class / header file needs to "know about", so does anything in class position need to know about class map. If not then don't include map.h. Try this reasoning on all 3 class definitions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900