Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Receiving very odd compiler Errors


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 tragic   Members   -  Reputation: 165

Like
0Likes
Like

Posted 30 June 2014 - 10:27 PM

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



Sponsor:

#2 Endurion   Crossbones+   -  Reputation: 3651

Like
13Likes
Like

Posted 30 June 2014 - 10:43 PM

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>

#3 tragic   Members   -  Reputation: 165

Like
0Likes
Like

Posted 30 June 2014 - 10:52 PM

 

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.



#4 Eck   Crossbones+   -  Reputation: 3095

Like
8Likes
Like

Posted 01 July 2014 - 08:45 AM

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



#5 georger.araujo   Members   -  Reputation: 821

Like
5Likes
Like

Posted 01 July 2014 - 07:21 PM

 

 

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS