Jump to content
  • Advertisement
Sign in to follow this  
MTclip

forward declaration for cyclic includes..

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey, I have a cyclic include thing going on, it should be fine because i am forward declaring.. whats goin on here
// perception.h
#pragma once

#include "agent.h"
// forward Declaration
class Agent;

class Perception
{
public:
	Agent* pClosestKin;
	Agent* pClosestMate;
	Agent* pClosestFood;
	Agent* pCloasestThreat;

	Perception(void);
	~Perception(void);
};

//agent.h
#pragma once
//other includes clipped//
#include "perception.h"

#define MUTATION 15

// forward declaration
class Perception;

class Agent : public WereIRenderable, public WereIFileable
{
protected:
	static std::map<std::string, Agent*> m_AgentMap;
	
public:
	static long* pAgentID;
	std::string m_location;

	WereModel * m_pModel;
	Behavior* m_pBehavior;
	Stats* m_pStats;
	AgentState m_state;
	Perception m_perception;
// rest of class clipped//

have i forward declared wrong? both of the classes compile if i dont try to mix them here is the error Agent.h(36): error C2079: 'Agent::m_perception' uses undefined class 'Perception' thanks

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
try


#ifndef SOME_NAME
#define SOME_NAME

// your code

#endif


might be worth a try

Share this post


Link to post
Share on other sites
Your forward declaraions are fine, but perception.h doesn't need to include agent.h because it only uses Agent as a pointer. Move that #include to perception.cpp, and the circular dependancy will go away.

Also, don't rely on #pragma once to prevent a header from being included more than once, because it's a compiler-specific extension. It's best to stick with the old fashioned method of include guards:


#ifndef INCLUDED_PERCEPTION_H_
#define INCLUDED_PERCEPTION_H_

/* the header */

#endif // INCLUDED_PERCEPTION_H_

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!