when i run my code, i get lots of undefined class errors, even though i have defined and included the files properly(i think).

here are the errors i'm getting:
------ Build started: Project: engine, Configuration: Debug Win32 ------
Compiling...
baseentity.cpp
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(13) : error C2079: 'CGlobals::controller' uses undefined class 'CEntityController'
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\baseentity.cpp(9) : error C2228: left of '.AddEntity' must have class/struct/union
type is 'int'
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\baseentity.cpp(59) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\baseentity.cpp(60) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
main.cpp
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(13) : error C2079: 'CGlobals::controller' uses undefined class 'CEntityController'
entitycontroller.cpp
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(13) : error C2079: 'CGlobals::controller' uses undefined class 'CEntityController'
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(7) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(13) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(19) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(28) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(45) : warning C4244: 'argument' : conversion from 'double' to 'clock_t', possible loss of data
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(46) : warning C4305: '+=' : truncation from 'double' to 'float'
Generating Code...
Build log was saved at "file://c:\Documents and Settings\tom\My Documents\Visual Studio 2008\Projects\engine\engine\Debug\BuildLog.htm"
engine - 4 error(s), 8 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

and this is the relevant code:
globals.h:

#ifndef GLOBALS_H
#define GLOBALS_H

#include "timer.h"
#include "id_manager.h"

class CEntityController;

struct CGlobals{
	float curtime;
	CTimer timer;
	IDM id_manager;
	CEntityController controller;
}*gpGlobals;

#endif //GLOBALS_H

entitycontroller.h:

#ifndef ENTITYCONTROLLER_H
#define ENTITYCONTROLLER_H

#include <vector>
#include "globals.h"

class CBase;
class CEntityController{
	std::vector<CBase*> m_vEntities;
	float m_fNextUpdateTime;
public:
	void SpawnEntities( );
	void ActivateEntities( );
	void ThinkEntities( );
	void DeleteEntities( );

	void Start( );
	void Loop( );
	void End( );

	void AddEntity( CBase *pEntity );
};

#endif //ENTITYCONTROLLER_H

any help would be appreciated

Ah, still working on the ol' engine I see!
Looking at the actual error and your code; I think in this instance, forward declaring the entitycontroller class is not working in globals.h. In fact thinking about it logically, forward declaring the class in globals.h isn't really appropriate either. The globals header only contains a struct and I'm guessing that there's no globals.cpp file which includes entitycontroller.h either, so therefore the compiler can't work out exactly what the entitycontroller class is in globals.h
Thus, you need to #include entitycontroller.h in globals.h. I'm pretty certain that will clear things up for you....Lose the forward declaration and just include the header for entitycontroller in globals.h

Cheers for now,
Jas.

Edited 6 Years Ago by JasonHippy: Why did I quote the entire original post??

Hey, I'm surprised anyone remembers my engine!
When I do what you said, I get these errors:

------ Build started: Project: engine, Configuration: Debug Win32 ------
Compiling...
baseentity.cpp
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(14) : error C2146: syntax error : missing ';' before identifier 'controller'
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\baseentity.cpp(9) : error C2039: 'controller' : is not a member of 'CGlobals'
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(10) : see declaration of 'CGlobals'
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\baseentity.cpp(9) : error C2228: left of '.AddEntity' must have class/struct/union
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\baseentity.cpp(59) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\baseentity.cpp(60) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
main.cpp
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(14) : error C2146: syntax error : missing ';' before identifier 'controller'
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
entitycontroller.cpp
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(14) : error C2146: syntax error : missing ';' before identifier 'controller'
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(7) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(13) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(19) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(28) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(45) : warning C4244: 'argument' : conversion from 'double' to 'clock_t', possible loss of data
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(46) : warning C4305: '+=' : truncation from 'double' to 'float'
Generating Code...
Build log was saved at "file://c:\Documents and Settings\tom\My Documents\Visual Studio 2008\Projects\engine\engine\Debug\BuildLog.htm"
engine - 11 error(s), 8 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I think it's because globals.h and entitycontroller.h are both including eachother

ok, well I could be wrong, but I don't think that entitycontroller.h needs to have globals.h included in it, I see no reference to CGlobals in there, so that can probably be removed. That may help.
If the entitycontroller class uses anything from globals.h in the implementation code (e.g. in entitycontroller.cpp), then it's probably best to include it there instead.

Not sure if that's a part of the problem or whether there's something obvious that we're not seeing, but it may be worth giving that a go!

That fixed it, but now I am getting a runtime error.

Unhandled exception at 0x004ccf99 in engine.exe: 0xC0000005: Access violation reading location 0x0000001c.

That is the error.
It points to this code from <vector>:

size_type size() const
		{	// return length of sequence
		return (_Mylast - _Myfirst);
		}

this is the code dealing with vectors:

#include "entitycontroller.h"
#include "globals.h"
#include "cbase_class.h"

CEntityController::CEntityController( )
{
}

void CEntityController::SpawnEntities( )
{
	for( int i = 0; i < m_vEntities.size( ); ++i )
		m_vEntities[i]->Spawn( );
}

void CEntityController::ActivateEntities( )
{
	for( int i = 0; i < m_vEntities.size( ); ++i )
		m_vEntities[i]->Activate( );
}

void CEntityController::ThinkEntities( )
{
	for( int i = 0; i < m_vEntities.size( ); ++i )
	{
		if( gpGlobals->curtime >= m_vEntities[i]->GetNextThinkTime( ) )
			m_vEntities[i]->Think( );
	}
}

void CEntityController::DeleteEntities( )
{
	for( int i = 0; i < m_vEntities.size( ); ++i )
		m_vEntities[i]->Delete( );
}

void CEntityController::AddEntity( CBase *pEntity )
{
	m_vEntities.push_back( pEntity );
}

void CEntityController::Start( )
{
	ActivateEntities( );
	SpawnEntities( );
}

void CEntityController::Loop( )
{
	if( gpGlobals->timer.elasped( 0.001 ) )
		gpGlobals->curtime += 0.001;
	ThinkEntities( );
}

void CEntityController::End( )
{
	DeleteEntities( );
}

Edited 6 Years Ago by tomtetlaw: it wouldn't upload

That's cool, at least we're making headway.
Do you know exactly which line of your code is throwing the error inside vector?
Try running in debug mode. When the error occurs and you get a message box about the error, select whatever option it is to break out of the program and into the offending line of code, that'll bring you out to the code you've highlighted in vector.

Sorry, I should point out, I've had a few ciders this evening, so I'm not fully compus mentis ATM. so apologies if I'm not entirely coherent in this post!

Anyway next, take a look at the call-stack and it should show you exactly which line of your code was responsible for causing the error to be thrown by the code in vector.

That should make it a lot easier to diagnose the problem.
If it doesn't become immediately apparent to you, then by all means post the details of the offending line of code and we can take a look!

Cheers for now,
Jas.

This article has been dead for over six months. Start a new discussion instead.