Jump to content
  • Advertisement
Sign in to follow this  

forward declaration for cyclic includes..

This topic is 4860 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
	Agent* pClosestKin;
	Agent* pClosestMate;
	Agent* pClosestFood;
	Agent* pCloasestThreat;


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

#define MUTATION 15

// forward declaration
class Perception;

class Agent : public WereIRenderable, public WereIFileable
	static std::map<std::string, Agent*> m_AgentMap;
	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
Guest Anonymous Poster

#ifndef SOME_NAME
#define SOME_NAME

// your code


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:


/* the header */


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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!