# Strange error when adding new constructor

This topic is 4172 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Okay, sry the topic might be a bit misleading, but I couldn´t think of something more fitting. Please take a look at this header I wrote:
#pragma once
#include "Entity.h"
#include "../Interfaces/IRenderable.h"

namespace PUKE
{
namespace Logic
{
class Entity;

class __declspec(dllexport) EntityView
{
public:
EntityView();
EntityView(Entity* e);
//EntityView(Entity* e, IRenderable* r);
~EntityView();

virtual void		Update();

void			AttachEntity(Entity* e);
void			DetachEntity(bool tellEntity = true);

PUKE::GFX::IRenderable* GetRenderable(){return this->m_pRenderable;}
void			SetRenderable(PUKE::GFX::IRenderable* in){this->m_pRenderable = in;}

protected:

Entity*			m_pEntity;
PUKE::GFX::IRenderable*	m_pRenderable;
};
};
};


Now this works like a charm. Except when I uncomment the third constructor EntityView(Entity* e, IRenderable* r). As soon as I add this constructor I get spilled with errors like this one: "error C2460: 'PUKE::Logic::EntityView::Entity' : uses 'PUKE::Logic::EntityView', which is being defined e:\coding\jnr\src\engine\gamelogic\EntityView.h(14) : see declaration of 'PUKE::Logic::EntityView'" Of course I get the missing type specifier errors then, too. As I just added the simple SetRenderable(...) method to the class that is not a critical problem, still I´m quite interested what the heck is going on there and why it´s okay to use an Entity* all over the place and a IRenderable*, too, but the compiler jumps at me as soon as I want to have that constructor. The most surprising thing to me is that the class Entity now seems to be a member of PUKE::Logic::EntityView, at least according to that error. I´m using VS2005, C++ and the DirectX SDK February 2006. Any ideas appreciated.

##### Share on other sites
Try just forward declaring IRenderable instead of including the IRenderable.h file. You may have references to the Entity class in IRenderable.h that is causing circular dependencies.

##### Share on other sites
nope, that didn´t change anything.
IRenderable.h doesn´t include another header that could cause a circular dependency.
I moved both includes to the corresponding .cpp file, and this is the current version of the header:
#pragma oncenamespace PUKE{namespace GFX{	class IRenderable;};namespace Logic{class Entity;class __declspec(dllexport) EntityView{public:	EntityView();	EntityView(Entity* e);//	EntityView(Entity* e, IRenderable* r = NULL);	~EntityView();	virtual void		Update();	void			AttachEntity(Entity* e);	void			DetachEntity(bool tellEntity = true);	PUKE::GFX::IRenderable* GetRenderable(){return this->m_pRenderable;}	void			SetRenderable(PUKE::GFX::IRenderable* in){this->m_pRenderable = in;}protected:	Entity*			m_pEntity;	PUKE::GFX::IRenderable*	m_pRenderable;};};};

Still, uncommenting the third constructor leads to the errors described in the first post.

##### Share on other sites
In your most recent post, you have the following two constructors:

	EntityView(Entity* e);//	EntityView(Entity* e, IRenderable* r = NULL);

Is setting r = NULL as a default parameter a typo? as it does not appear in your first post. If it is not a typo, then you will get an error because there is ambiguity as to which constructor to use. EntityView(myEntity) - should this use the first or the second constructor (utilizing the default parameter)? The compiler has no way of knowing.

##### Share on other sites
What are the first few errors that crop up? The one you posted would most likely only occur after the parser was thoroughly confused. In a long list of errors, usually only the first 1 or 2 are meaningful.

##### Share on other sites
okay, I feel stupid again... like many times before I just forgot to tell the compiler that IRenderable belongs to PUKE::GFX, so it should have been:
EntityView(Entity* e, PUKE::GFX::IRenderable* r);

However, setting NULL as default value for that parameter doesn´t work.
EntityView(Entity* e, PUKE::GFX:IRenderable* r = NULL);

results in "error C2065: 'NULL' : undeclared identifier", using 0 as default value works, though....

##### Share on other sites
Yes, in C++ the universal null pointer value is now spelled 0. :)