Receiving very odd compiler Errors

Started by
3 comments, last by georger.araujo 9 years, 9 months ago

So as the title states im receiving some odd errors with a couple of class that im working on. Im trying to implement the Entity Component System example from Game Programming Gems 6 and im getting a lot of issues with it from just doing test compiles every once in a while to check for syntax errors and such.

These classes are without definitions yet but I don't think that would be an issue.


#pragma once
#include <string>
#include <map>
#include "Component.h"

class GameObject
{
public:
	GameObject(const std::string GameObjectID);
	virtual ~GameObject()=0;

	const std::string GetID();
	void ClearComponents();

private:
	std::string mGameObjectID;
	std::map<const std::string, Component*> ComponentTable;
};



#pragma once
#include <string>
#include "GameObject.h"

class Component
{
public:
	Component();
	virtual ~Component()=0;

	virtual const std::string componentID() const = 0;

	virtual void Update();

	void SetOwner(GameObject* go);
	GameObject* GetOwner() const;

private:
	GameObject* mOwner;
};

Warning	4	warning C4183: 'GetOwner': missing return type; assumed to be a member function returning 'int'	c:\users\\code\c++\engine\engine\component.h	16	1	Engine
Error	3	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\users\\code\c++\engine\engine\component.h	16	1	Engine
Error	6	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\users\\code\c++\engine\engine\component.h	19	1	Engine
Error	9	error C2143: syntax error : missing ';' before '}'	c:\users\\code\c++\engine\engine\gameobject.h	18	1	Engine
Error	11	error C2143: syntax error : missing ';' before '}'	c:\users\\code\c++\engine\engine\component.h	20	1	Engine
Error	12	error C2143: syntax error : missing ';' before '}'	c:\users\\code\c++\engine\engine\component.cpp	12	1	Engine
Error	10	error C2143: syntax error : missing ';' before '{'	c:\users\\code\c++\engine\engine\component.h	6	1	Engine
Error	2	error C2143: syntax error : missing ';' before '*'	c:\users\\code\c++\engine\engine\component.h	16	1	Engine
Error	5	error C2143: syntax error : missing ';' before '*'	c:\users\\code\c++\engine\engine\component.h	19	1	Engine
Error	7	error C2065: 'Component' : undeclared identifier	c:\users\\code\c++\engine\engine\gameobject.h	17	1	Engine
Error	1	error C2061: syntax error : identifier 'GameObject'	c:\users\\code\c++\engine\engine\component.h	15	1	Engine
Error	8	error C2059: syntax error : '>'	c:\users\\code\c++\engine\engine\gameobject.h	17	1	Engine
Error	13	error C1004: unexpected end-of-file found	c:\users\\code\c++\engine\engine\component.cpp	12	1	Engine

Advertisement

You've got circular inclusions for GameObject and Component.

Since you seem to only use pointers to each other remove the "#include "GameObject.h" from Component.h and vice versa. Add a forward declaration to each header.

Component.h

...
class GameObject;
 
class Component
{
  ...

GameObject.h

...
class Component;
 
class GameObject
{
  ...

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

You've got circular inclusions for GameObject and Component.

Since you seem to only use pointers to each other remove the "#include "GameObject.h" from Component.h and vice versa. Add a forward declaration to each header.


...
class GameObject;
 
class Component
{
  ...

GameObject.h


...
class Component;
 
class GameObject
{
  ...

Seems to have done the trick and has given me one more C++ topic to research. Thank you.

Basically "circular inclusion" is when class one's header file (Component.h) needs to use class two's header file (GameObject.h). And class two's header file needs to use class one's header file.

You use "forward declaration" to give the compiler a heads up, "Hey compiler. I know you don't know what GameObject is but it's going to be a class, and I need a pointer to it. I promise we'll have implementation for it later, but for now just trust me that I need a GameObject pointer in Component." :)

This is a very rough definition, but it should give you an idea of what these things are before continuing your research.

- Eck

EckTech Games - Games and Unity Assets I'm working on
Still Flying - My GameDev journal
The Shilwulf Dynasty - Campaign notes for my Rogue Trader RPG

You've got circular inclusions for GameObject and Component.

Since you seem to only use pointers to each other remove the "#include "GameObject.h" from Component.h and vice versa. Add a forward declaration to each header.


...
class GameObject;
 
class Component
{
  ...

GameObject.h


...
class Component;
 
class GameObject
{
  ...

Seems to have done the trick and has given me one more C++ topic to research. Thank you.

GameDev.net published this really nice article about this and other C/C++ code organization problems. A very good read.

This topic is closed to new replies.

Advertisement