Jump to content
  • Advertisement
Sign in to follow this  
storage

Enginuity trouble

This topic is 4865 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

I'm having problems compiling the smart pointers used in the Enginuity, Part II article. I'm using Microsoft Visual C++ 2005 Beta 2, if it helps to know! I'm getting these errors:
Error	1	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\test\mmanager.h	38
Error	2	error C4430: missing type specifier - int assumed. Note: C++ does not support default-int	c:\test\mmanager.h	44
here:
	inline operator =(const CMMPointer<T> &p) // this line
	{
		if(obj)obj->Release();
		obj=p.obj;
		if(obj)obj->AddRef();
	}
	inline operator =(T* o) // this line
	{
		if(obj)obj->Release();
		obj=o;
		if(obj)obj->AddRef();
	}



Any ideas? Thanks in advance! :) edit: new subject [Edited by - storage on July 24, 2005 9:51:30 PM]

Share this post


Link to post
Share on other sites
Advertisement
Note how the functions have no return type? That is causing the error. Simply add a return type (and return statement) - for the first function I suggest CMMPointer<T> &p, and for the second I suggest T *.

HTH and cheers!

Share this post


Link to post
Share on other sites
I recomend the same return type for both of them. Fyhuang's method is inconsistant with what is normal for an assignment operator.


// I am making the assumption that your class is:
template <class T>
class CMMPointer
{
inline CMMPointer<T>& operator =(const CMMPointer<T>& p)
{
if(obj)obj->Release();
obj=p.obj;
if(obj)obj->AddRef();
return *this;
}
inline CMMPointer<T>& operator =(T* o)
{
if(obj)obj->Release();
obj=o;
if(obj)obj->AddRef();
return *this;
}
};


Note that if you don't want them to return anything (which is, again, inconsistant), then you need to drop the return type void in before the operator keyword. The only things that don't need a return type are constructors, destructors, and conversion operators (the assignment operator is none of these).

Share this post


Link to post
Share on other sites
I have another problem with Enginuity, the garbage collection throws a runtime error at me when I'm trying to collect the dead objects (in void IMMObject::CollectGarbage()).

mmanager.cpp:

#include "engine.h"


std::list<IMMObject *> IMMObject::liveObjects;
std::list<IMMObject *> IMMObject::deadObjects;

IMMObject::IMMObject()
{
liveObjects.push_back(this);
refCount=0;
}

IMMObject::~IMMObject()
{

}

void IMMObject::CollectGarbage()
{
for(std::list<IMMObject*>::iterator it=deadObjects.begin();it!=deadObjects.end();)
{
IMMObject *o=(*it);
delete o; // here -------------------------------------------
it++;
}
deadObjects.clear();
}

void IMMObject::AddRef()
{
refCount++;
}

void IMMObject::Release()
{
refCount--;
if(refCount<=0)
{
//remove self from live list
liveObjects.remove(this);
//add self to dead list
deadObjects.push_back(this);
}
}

void IMMObject::CollectRemainingObjects(bool bEmitWarnings)
{
CollectGarbage();
for(std::list<IMMObject*>::iterator it=liveObjects.begin();it!=liveObjects.end();it++)
{
IMMObject *o=(*it);
if(bEmitWarnings)
{
//copy the object to a temporary buffer so that our '10 bytes' message doesn't
//cause an access violation
char szBuf[11]; ZeroMemory(szBuf,11);
memcpy(szBuf,o,min(o->size(),10));
CLog::Get().Write(LOG_APP,IDS_UNRELEASED_OBJECT,o,o->size(),szBuf);
}
delete o;
}
liveObjects.clear();
}




Error:
Unhandled exception at 0x0041263b in test.exe: 0xC0000005: Access violation reading location 0xfeeefeee.


Any ideas?

Share this post


Link to post
Share on other sites
0xFEEEFEEE: Used by Microsoft's C++ compiler to mark the storage area of a deleted class in debug mode

In other words, you're dereferencing a pointer contained in memory that has been deleted.

This following is a small example that will cause it:

// A class
class Foo { public: int* bar; };

// The code to generate the same error:
int baz;
Foo* myfoo = new Foo;
myfoo->bar = &baz;
delete myfoo; // sets the contents of myfoo (ie: "bar") to 0xFEEEFEEE in debug mode.
print(*myfoo->bar); // BANG! dereferenced bar (0xFEEEFEEE).


MSVC specificly sets the value to that specificly to find this kind of error.

Share this post


Link to post
Share on other sites
Ah! Thanks! :)

The error occurred when I tried to collect garbage after the object had been deleted, then recreated.

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!