Incomplete type is not allowed
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Incomplete type is not allowed

Hybrid View

  1. #1
    Join Date
    Dec 2010
    Posts
    523

    Incomplete type is not allowed

    Code:
    #include "..\Objects\Objects.h"
    
    class Idle;
    class Objects;
    class Goods;
    
    class Activity
    {
    public:
    	Objects *Actor;
    	Goods *Target;
    	Activity() : Actor(0), Target(0) { }
    	Activity( Objects* actor, Goods* target )
    	{
    		Actor = actor;
    		Target = target;
    	}
    
    	virtual bool OnUpdate(float seconds) = 0;
    
    	void Update(float seconds)
    	{
    		if (OnUpdate(seconds))
    		{
    			Actor->activity = new Idle(Actor, NULL); <<<< incomplete type is not allowed
                            // activity is of type Activity *
    		}
    	}
    
    	Activity *FindBestActivity(Objects *actor)
    	{
    		return NULL;
    	}
    
    
    };
    
    /////////////////////
    #include "..\Objects\Objects.h"
    #include "Activity.h"
    
    #define MAX_IDLE_TIME 8
    #define ACTIVITY_IDLE_ENERGY 1.0
    
    class Objects;
    class Activity;
    
    class Idle : public Activity
    {
    private:
    	float mTimeInIdle;
    
    public:
    	Idle() : mTimeInIdle(0)	{ }
    	Idle(Objects *actor, Goods *target) : Activity(actor, target)
    	{
    
    	}
    
    	bool OnUpdate(float seconds)
    	{
    		mTimeInIdle += seconds;
    		if (mTimeInIdle >= MAX_IDLE_TIME)
    		{
    			Actor->activity = FindBestActivity(Actor);
    		}
    
    
    		Actor->energy += ACTIVITY_IDLE_ENERGY * seconds;
    		return false;
    	}
    
    
    };
    Please help fix this problem.
    Thanks
    Jack

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,196

    Re: Incomplete type is not allowed

    You cannot access Actor->activity unless the definition of Objects is known. Perhaps you should define the Update member function in a source file instead, where the header containing the definition of Objects can be included (presumably you are only using a forward declaration here to break a recursive dependency or something).
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center