Jump to content

  • Log In with Google      Sign In   
  • Create Account

claesson92

Member Since 11 Jul 2007
Offline Last Active Aug 07 2014 06:10 AM

Topics I've Started

boost::property_tree acces violation

18 June 2010 - 11:18 PM

Hi, i'm trying to use boost::property_tree::ptree to read data from an XML file. The problem is that i get access violation errors and such when i try to read the elements.

Here is the XML file:
<?xml version="1.0" encoding="utf-8"?>

<clientConfig>
<graphics>
<renderer>GL</renderer> <!-- GL, D3D8, D3D9, SW, BR -->
<resolutionWidth>1024</resolutionWidth>
<resolutionHeight>768</resolutionHeight>
<bitDepth>32</bitDepth>
<fullscreen>true</fullscreen>
<stencilBuffer>false</stencilBuffer>
<vsync>false</vsync>
</graphics>
</clientConfig>





Here is the C++ code:
//Create a boost property tree
boost::property_tree::ptree proptree;

//Read the XML file
try
{
boost::property_tree::read_xml(full_path, proptree, boost::property_tree::xml_parser::no_comments);

tog::ClientConfig::m_rendererString = proptree.get<std::string>("clientConfig.graphics.renderer", "GL");

unsigned int width = proptree.get<unsigned int>("clientConfig.graphics.resolutionWidth", 1024);
unsigned int height = proptree.get<unsigned int>("clientConfig.graphics.resoltuionHeight", 768);
tog::ClientConfig::m_windowResolution = irr::core::dimension2d<irr::u32>(width, height);

tog::ClientConfig::m_bitDepth = proptree.get<unsigned short>("clientConfig.graphics.bitDepth", 32);

if(proptree.get<std::string>("clientConfig.graphics.fullscreen", "false") == "true")
{
tog::ClientConfig::m_fullscreen = true;
}
else
{
tog::ClientConfig::m_fullscreen = false;
}

if(proptree.get<std::string>("clientConfig.graphics.stencilBuffer", "false") == "true")
{
tog::ClientConfig::m_stencilBuffer = true;
}
else
{
tog::ClientConfig::m_stencilBuffer = false;
}

if(proptree.get<std::string>("clientConfig.graphics.vsync", "false") == "true")
{
tog::ClientConfig::m_vsync = true;
}
else
{
tog::ClientConfig::m_vsync = false;
}
}
catch(boost::property_tree::xml_parser_error& e)
{
throw tog::Exception("Unable to open and parse XML config file \"" + full_path + "\". " + e.what());
}
catch(...)
{

}





I get access violations at every proptree.get().
This is what i get from the error:
First-chance exception at 0x00423da0 in Tales of Garia.exe: 0xC0000005: Access violation reading location 0xcdcdcde5.
Unhandled exception at 0x00423da0 in Tales of Garia.exe: 0xC0000005: Access violation reading location 0xcdcdcde5.


That's the exception i get at the first proptree.get(). Visual Studio opens "xstring" at this position:
else if (this->_BUF_SIZE <= this->_Myres)
{ // copy any leftovers to small buffer and deallocate
_Elem *_Ptr = this->_Bx._Ptr;
if (0 < _Newsize)
_Traits::copy(this->_Bx._Buf, _Ptr, _Newsize);
this->_Alval.deallocate(_Ptr, this->_Myres + 1);
}



What might be the problem here? The file path is correct, and no exception is thrown before this.

[Edited by - claesson92 on June 20, 2010 3:19:35 PM]

[C++] Namespace problem

15 February 2010 - 09:40 PM

Hi, i have a few classes in namespaces. They worked earlier, but now after i wrote some more code, they can't find each other. Here is all code: http://code.google.com/p/cgdk/source/browse/#svn/trunk/CGDKFramework The important files for this problem is _stdlibrary.hpp, Vector.hpp & Vector2.hpp Here is all errors i get:
Error	1	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	2	error C2504: 'Vector' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	3	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	4	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	5	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	6	error C2143: syntax error : missing ')' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	7	error C2143: syntax error : missing ';' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	8	error C2059: syntax error : ')'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	9	error C2238: unexpected token(s) preceding ';'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	10	error C2327: 'CGDK::core::Vector2<T>::Vector' : is not a type name, static, or enumerator	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	11	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	12	error C2061: syntax error : identifier 'Vector'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	13	error C2995: 'CGDK::core::Vector2<T>::Vector2(void)' : function template has already been defined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	91	
Error	14	error C2039: 'Collection' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	15	error C2504: 'Collection' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	16	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	17	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	18	error C2504: 'Vector' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	19	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	20	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	21	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	22	error C2143: syntax error : missing ')' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	23	error C2143: syntax error : missing ';' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	24	error C2059: syntax error : ')'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	25	error C2238: unexpected token(s) preceding ';'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	26	error C2327: 'CGDK::core::Vector2<T>::Vector' : is not a type name, static, or enumerator	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	27	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	28	error C2061: syntax error : identifier 'Vector'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	29	error C2995: 'CGDK::core::Vector2<T>::Vector2(void)' : function template has already been defined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	91	
Error	30	error C2039: 'Collection' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	31	error C2504: 'Collection' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	32	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	33	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	34	error C2504: 'Vector' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	35	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	36	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	37	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	38	error C2143: syntax error : missing ')' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	39	error C2143: syntax error : missing ';' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	40	error C2059: syntax error : ')'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	41	error C2238: unexpected token(s) preceding ';'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	42	error C2327: 'CGDK::core::Vector2<T>::Vector' : is not a type name, static, or enumerator	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	43	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	44	error C2061: syntax error : identifier 'Vector'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	45	error C2995: 'CGDK::core::Vector2<T>::Vector2(void)' : function template has already been defined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	91	
Error	46	error C2039: 'Collection' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	47	error C2504: 'Collection' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	48	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	49	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	50	error C2504: 'Vector' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	51	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	52	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	53	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	54	error C2143: syntax error : missing ')' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	55	error C2143: syntax error : missing ';' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	56	error C2059: syntax error : ')'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	57	error C2238: unexpected token(s) preceding ';'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	58	error C2327: 'CGDK::core::Vector2<T>::Vector' : is not a type name, static, or enumerator	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	59	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	60	error C2061: syntax error : identifier 'Vector'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	61	error C2995: 'CGDK::core::Vector2<T>::Vector2(void)' : function template has already been defined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	91	
Error	62	error C2039: 'Collection' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	63	error C2504: 'Collection' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	64	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	65	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	66	error C2504: 'Vector' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	67	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	68	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	69	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	70	error C2143: syntax error : missing ')' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	71	error C2143: syntax error : missing ';' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	72	error C2059: syntax error : ')'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	73	error C2238: unexpected token(s) preceding ';'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	74	error C2327: 'CGDK::core::Vector2<T>::Vector' : is not a type name, static, or enumerator	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	75	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	76	error C2061: syntax error : identifier 'Vector'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	77	error C2995: 'CGDK::core::Vector2<T>::Vector2(void)' : function template has already been defined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	91	
Error	78	error C2039: 'Collection' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	79	error C2504: 'Collection' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	80	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	81	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	82	error C2504: 'Vector' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	83	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	11	
Error	84	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	85	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	86	error C2143: syntax error : missing ')' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	87	error C2143: syntax error : missing ';' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	88	error C2059: syntax error : ')'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	89	error C2238: unexpected token(s) preceding ';'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	24	
Error	90	error C2327: 'CGDK::core::Vector2<T>::Vector' : is not a type name, static, or enumerator	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	91	error C2039: 'Vector' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	92	error C2061: syntax error : identifier 'Vector'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	85	
Error	93	error C2995: 'CGDK::core::Vector2<T>::Vector2(void)' : function template has already been defined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector2.hpp	91	
Error	94	error C2039: 'Collection' : is not a member of 'CGDK::core'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	95	error C2504: 'Collection' : base class undefined	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	
Error	96	error C2143: syntax error : missing ',' before '<'	c:\documents and settings\nti\mina dokument\visual studio 2005\projects\cgdk\cgdkframework\vector.hpp	12	





[C++] Heap error/memory freeing

19 January 2010 - 06:09 AM

I'm having a problem which seems to only occour in debug mode. I get an error (at runtime) about some heap error, and also says there is a bug in the program. I know/think that it has to do with that i'm either using freed memory, or freeing something twice. The code is based on the enguinity guides. When i get the error i get some info about a triggered breakpoint in xutility. The error is caused by MemoryObject::collectRemaining(). Or more specifically, the line "delete o" in that method. I seem to delete/free something which already is freed. Or, something is trying to free it afterwards. I'm not able to fix this problem though. The debugger tells me the problem happends in free.c at this line:
retval = HeapFree(_crtheap, 0, pBlock);

This is not anything i've written. It's related to delete. In the following code, much has been stripped away. There are a few calls to functions such as getLength(), m_getAllocatedElements() and so, but i think their names explains what they does. Here are the (stripped) relevant code: main.cpp
#include "CGDK.hpp" //This includes Collection.hpp, MemoryObject.hpp, MemoryPointer.hpp and some standard C++ headers

using namespace std;
using namespace CGDK::core;

int main(int argc, char *argv[])
{
	MemoryPointer<Vector<int>> m = new Vector<int>(25);

	MemoryObject::collectRemaining();

	return 0;
}


MemoryPointer.hpp - Full code
#include "_stdlibrary.hpp" //Includes some standard c++ headers and my own classes

//Class definition...

template<typename T>
CGDK::core::MemoryPointer<T>::MemoryPointer()
{
	m_object = 0;
}

template<typename T>
CGDK::core::MemoryPointer<T>::MemoryPointer(T *obj)
{
	m_object = 0;
	*this = obj;
}
template<typename T>
CGDK::core::MemoryPointer<T>::~MemoryPointer()
{
	if(m_object)
	{
		m_object->release();
	}
}

template<typename T>
void CGDK::core::MemoryPointer<T>::operator=(T *obj)
{
	//Decrement the reference counter if the is an object
	if(m_object)
	{
		m_object->release();
	}

	m_object = obj;

	//Increment the reference counter...
	if(m_object)
	{
		m_object->addReference();
	}
}

template<typename T>
T* CGDK::core::MemoryPointer<T>::operator->() const
{
	CGDK_ASSERT(m_object != 0, "Tried to -> on a NULL smart pointer");

	return m_object;
}




Vector.hpp - Full code
//Some includes

template<typename T>
class Vector : public CGDK::core::Collection<T>
{
    //Some code
};

template<typename T>
void CGDK::core::Vector<T>::m_initVector(T initvalue)
{
	m_maxSize = 0;

	//Set the initial value of new elements
	setInitialValue(initvalue);
}

template<typename T>
CGDK::core::Vector<T>::Vector() : CGDK::core::Collection<T>::Collection(10, 5)
{
	m_initVector();
}

template<typename T>
CGDK::core::Vector<T>::Vector(unsigned int size, T initvalue) : CGDK::core::Collection<T>::Collection(size, 5)
{
	m_initVector(initvalue);
}

template<typename T>
CGDK::core::Vector<T>::~Vector()
{

}

template<typename T>
void CGDK::core::Vector<T>::setMaximumSize(unsigned int max)
{
	m_maxSize = max;
}

template<typename T>
unsigned int CGDK::core::Vector<T>::getMaximumSize()
{
	return m_maxSize;
}


Collection.hpp - Full code
//Includes

template<typename T>
class Collection<T> : public CGDK::core::MemoryObject
{
    //Some code...
};

template<typename T>
void CGDK::core::Collection<T>::m_realloc(unsigned long elements)
{
	unsigned long _oldsize = m_allocatedElements;

	try
	{
		m_memPointer = new T[elements];
		m_allocatedElements = elements;
	}
	catch(std::bad_alloc e)
	{
		CGDK_THROW("Unable to (re)allocate memory");
	}
	
	for(unsigned long i = _oldsize; i < m_allocatedElements; i++)
	{
		set(i, m_initValue);
	}
}

template<typename T>
void CGDK::core::Collection<T>::m_pushBack(T val)
{
	if(m_getFreeElements() == 0)
	{
		//We need to allocate more memory
		m_grow();
	}

	m_memPointer[m_usedElements] = val;
	m_usedElements++;
}

template<typename T>
void CGDK::core::Collection<T>::m_init(unsigned long elements, unsigned int growth)
{
	m_initValue = static_cast<T>(0);
	m_growth = growth;
	m_allocatedElements = elements;
	m_usedElements = 0;

	try
	{
		m_memPointer = new T[elements];
	}
	catch(std::bad_alloc e)
	{
		CGDK_THROW("Unable to allocate memory");
	}
}

template<typename T>
CGDK::core::Collection<T>::Collection()
{
	m_init(5, 5);
}

template<typename T>
CGDK::core::Collection<T>::Collection(unsigned long elements, unsigned int growth)
{
	m_init(elements, growth);
}

template<typename T>
CGDK::core::Collection<T>::~Collection()
{
	delete[] m_memPointer;
}






MemoryObject.cpp - This is where it crashes - Full code
#include "MemoryObject.hpp" //Contains the class definition and some includes
#include "Error.hpp"

std::list<CGDK::core::MemoryObject*> CGDK::core::MemoryObject::m_liveObjects;
std::list<CGDK::core::MemoryObject*> CGDK::core::MemoryObject::m_deadObjects;

void CGDK::core::MemoryObject::addReference()
{
	++m_referenceCount;
}

void CGDK::core::MemoryObject::release()
{
	--m_referenceCount;

	if(m_referenceCount <= 0)
	{
		m_liveObjects.remove(this);
		m_deadObjects.push_back(this);
	}
}

CGDK::core::MemoryObject::MemoryObject()
{
	m_liveObjects.push_back(this);
	//m_listPosition = static_cast<unsigned long>(m_liveObjects.size()) - 1;

	//Set the initial reference count to 0
	m_referenceCount = 0;
}

CGDK::core::MemoryObject::~MemoryObject()
{
}

void CGDK::core::MemoryObject::collectGarbage()
{
	for(std::list<MemoryObject*>::iterator it = m_deadObjects.begin(); it != m_deadObjects.end(); it++)
	{
		MemoryObject *o = (*it);
		delete(o);
		it++;
	}

	m_deadObjects.clear();
}

void CGDK::core::MemoryObject::collectRemaining()
{
	collectGarbage();

	for(std::list<MemoryObject*>::iterator it = m_liveObjects.begin(); it != m_liveObjects.end(); it++)
	{
		CGDK::core::MemoryObject *o=(*it);
		delete o; ///////// <-- This is where it crashes
	}

	m_liveObjects.clear();
}




Sorry for all that code, but i didn't want to miss anything, if the error were caused by something i didn't expect. [Edited by - claesson92 on January 20, 2010 2:14:36 AM]

Unexpected variable change

18 January 2010 - 12:18 AM

In thoose two classes, the program crashes as i'm trying to allocate a huge ammount of memory. This is beacause of m_allocatedElements and m_usedElements somewhere jumps from it's start value to a huge value.

#pragma once

#include "_stdlibrary.hpp"

namespace CGDK
{
	namespace core
	{
		template<typename T>
		class Collection : public MemoryObject
		{
		private:
			unsigned int m_growth;
			unsigned int m_allocatedElements;
			unsigned int m_usedElements;

			T *m_memPointer;
			T m_initValue;

		protected:
			bool m_isValidPos(unsigned long pos);
			void m_testValidPos(unsigned long pos);
			void m_realloc(unsigned long elements);
			unsigned long m_getAllocatedElements();
			unsigned long m_getFreeElements();
			unsigned long m_getUsedElements();
			void m_grow();
			void m_pushBack(T val);

		public:
			Collection();
			Collection(unsigned long elements, unsigned int growth = 5);
			virtual ~Collection();

			virtual void set(unsigned long pos, T val);
			virtual T get(unsigned long pos);
			virtual T& getReference(unsigned long pos);

			virtual void setGrowth(unsigned int growth);
			virtual unsigned int getGrowth();

			virtual void erase(unsigned long pos);
			virtual void setInitialValue(T val);
			virtual void fill(T value = m_initValue);
			virtual void clear();
			virtual void resize(unsigned long size);
			virtual unsigned long getLength();
			virtual bool isEmpty();

			template<typename T2>
			bool contains(T2 val);

			virtual T& operator[](unsigned long pos);
			virtual bool operator==(CGDK::core::Collection<T> collection);
			virtual bool operator!=(CGDK::core::Collection<T> collection);

			//Memory size
			CGDK_GETMEMORYSIZE_METHOD;
		};
	}
}

template<typename T>
bool CGDK::core::Collection<T>::m_isValidPos(unsigned long pos)
{
	bool _isok = (pos < getLength());
	CGDK_ASSERT(_isok, "Position out of bounds");

	if(_isok)
	{
		_isok = !isEmpty();
	}

	CGDK_ASSERT(_isok, "No elements exists");

	return _isok;
}

template<typename T>
void CGDK::core::Collection<T>::m_testValidPos(unsigned long pos)
{
	m_isValidPos(pos);
}

template<typename T>
void CGDK::core::Collection<T>::m_realloc(unsigned long elements)
{
	unsigned long _oldsize = m_allocatedElements;

	try
	{
		m_memPointer = new T[elements];
	}
	catch(std::bad_alloc e)
	{
		CGDK_THROW("Unable to (re)allocate memory");
	}

	m_allocatedElements = elements;

	for(unsigned long i = _oldsize; i < m_allocatedElements; i++)
	{
		set(i, m_initValue);
	}
}

template<typename T>
unsigned long CGDK::core::Collection<T>::m_getAllocatedElements()
{
	return m_allocatedElements;
}

template<typename T>
unsigned long CGDK::core::Collection<T>::m_getFreeElements()
{
	return m_allocatedElements - m_usedElements;
}

template<typename T>
unsigned long CGDK::core::Collection<T>::m_getUsedElements()
{
	return m_allocatedElements - m_getFreeElements();
}

template<typename T>
void CGDK::core::Collection<T>::m_grow()
{
	m_realloc(m_getAllocatedElements() + getGrowth());
}

template<typename T>
void CGDK::core::Collection<T>::m_pushBack(T val)
{
	if(m_getFreeElements() == 0)
	{
		//We need to allocate more memory
		m_grow();
	}

	m_memPointer[m_usedElements] = val;
	m_usedElements++;
}

template<typename T>
CGDK::core::Collection<T>::Collection()
{
#ifndef CGDK_RELEASE
	setDebugName("Collection", CGDK_T_TYPE);
#endif

	Collection<T>(5, 5);
}

template<typename T>
CGDK::core::Collection<T>::Collection(unsigned long elements, unsigned int growth)
{
	m_initValue = static_cast<T>(0);
	m_growth = growth;
	m_allocatedElements = elements;
	m_usedElements = 0;

	try
	{
		m_memPointer = new T[elements];
	}
	catch(std::bad_alloc e)
	{
		CGDK_THROW("Unable to allocate memory");
	}
}

template<typename T>
CGDK::core::Collection<T>::~Collection()
{
}

template<typename T>
void CGDK::core::Collection<T>::setGrowth(unsigned int growth)
{
	m_growth = growth;
}

template<typename T>
unsigned int CGDK::core::Collection<T>::getGrowth()
{
	return m_growth;
}

template<typename T>
void CGDK::core::Collection<T>::set(unsigned long pos, T val)
{
	if(m_isValidPos(pos))
	{
		m_memPointer[pos] = val;
	}
}

template<typename T>
T CGDK::core::Collection<T>::get(unsigned long pos)
{
	m_testValidPos(pos);

	return m_memPointer[pos];
}

template<typename T>
T& CGDK::core::Collection<T>::getReference(unsigned long pos)
{
	m_testValidPos(pos);

	return m_memPointer[pos];
}

template<typename T>
void CGDK::core::Collection<T>::erase(unsigned long pos)
{
	if(m_isValidPos(pos))
	{
		for(unsigned long i = pos + 1; i < getLength(); i++)
		{
			m_memPointer[pos - 1] = m_memPointer[pos];
		}

		m_memPointer[getLength() - 1] = m_initValue;
		m_usedElements--;
	}
}

template<typename T>
void CGDK::core::Collection<T>::setInitialValue(T val)
{
	m_initValue = val;
}

template<typename T>
void CGDK::core::Collection<T>::fill(T val)
{
	for(unsigned long i = 0; i < getLength(); i++)
	{
		set(i, val);
	}
}

template<typename T>
void CGDK::core::Collection<T>::clear()
{
	fill(static_cast<T>(0));
}

template<typename T>
void CGDK::core::Collection<T>::resize(unsigned long size)
{
	m_usedElements = size;
	m_realloc(size);
}

template<typename T>
unsigned long CGDK::core::Collection<T>::getLength()
{
	return m_usedElements;
}

template<typename T>
bool CGDK::core::Collection<T>::isEmpty()
{
	return (getLength() == 0);
}

template<typename T>
template<typename T2>
bool CGDK::core::Collection<T>::contains(T2 val)
{
	T _val = static_cast<T>(val);

	for(unsigned long i = 0; i < getLength(); i++)
	{
		if(get(i) == _val)
		{
			return true;
		}
	}

	return false;
}

template<typename T>
T& CGDK::core::Collection<T>::operator [](unsigned long pos)
{
	m_testValidPos(pos);

	return m_memPointer[pos];
}

template<typename T>
bool CGDK::core::Collection<T>::operator ==(CGDK::core::Collection<T> collection)
{
	if(collection.getLength() == getLength())
	{
		for(unsigned long i = 0; i < getLength(); i++)
		{
			if(collection[i] != get(i))
			{
				return false;
			}
		}

		return true;
	}
	else
	{
		return false;
	}
}

template<typename T>
bool CGDK::core::Collection<T>::operator !=(CGDK::core::Collection<T> collection)
{
	return !(*this == collection);
}







#pragma once

#include "_stdlibrary.hpp"
#include "Collection.hpp"

namespace CGDK
{
	namespace core
	{
		template<typename T>
		class Vector : public CGDK::core::Collection<T>
		{
		private:
			unsigned int m_maxSize;

			static unsigned int m_getLongestSize(CGDK::core::Vector<T> vector);
			static unsigned int m_getLongestSize(std::vector<T> stdvec);

		public:
			//Constructors
			Vector();
			Vector(unsigned int size, T initvalue = static_cast<T>(0));
			Vector(std::vector<T> stdvec);

			//Destructor
			 ~Vector();

			//Memory size
			CGDK_GETMEMORYSIZE_METHOD;

			//Get a subvector (like a substring)
			CGDK::core::Vector<T> getSubVector(unsigned int start, unsigned int length);

			//Set a maximum size. Is used by Vector2 and Vector3
			void setMaximumSize(unsigned int max);
			unsigned int getMaximumSize();

			//Overloaded operators
			template<typename T2>
			CGDK::core::Vector<T> operator+(T2 val);
			template<typename T2>
			CGDK::core::Vector<T>& operator+=(T2 val);

			template<typename T2>
			CGDK::core::Vector<T> operator-(T2 val);
			template<typename T2>
			CGDK::core::Vector<T>& operator-=(T2 val);

			template<typename T2>
			CGDK::core::Vector<T> operator*(T2 val);
			template<typename T2>
			CGDK::core::Vector<T>& operator*=(T2 val);

			template<typename T2>
			CGDK::core::Vector<T> operator/(T2 val);
			template<typename T2>
			CGDK::core::Vector<T>& operator/=(T2 val);

			template<typename T2>
			CGDK::core::Vector<T> operator%(T2 val);
			template<typename T2>
			CGDK::core::Vector<T>& operator%=(T2 val);

			bool operator<(CGDK::core::Vector<T> vec);
			bool operator<=(CGDK::core::Vector<T> vec);

			bool operator>(CGDK::core::Vector<T> vec);
			bool operator>=(CGDK::core::Vector<T> vec);

			CGDK::core::Vector<T> operator++();
			CGDK::core::Vector<T> operator++(int);
			CGDK::core::Vector<T> operator--();
			CGDK::core::Vector<T> operator--(int);

			//bool operator!=(CGDK::core::Vector<T> vec);
			//bool operator==(CGDK::core::Vector<T> vec);

			//Append elements/vector to the Vector
			void add(T element);
			void add(CGDK::core::Vector<T> vector);
			void add(std::vector<T> stdvec);

			//Removes all duplicates
			void unique();

			inline real getSum();
			inline real getAverage();
			inline real getMedian();

			//
			inline real getDotProduct(CGDK::core::Vector<T> vec);
		};
	}
}

template<typename T>
CGDK::core::Vector<T>::Vector()
{
#ifndef CGDK_RELEASE
	setDebugName("Vector", CGDK_T_TYPE);
#endif

	m_maxSize = 0;
}

template<typename T>
CGDK::core::Vector<T>::Vector(unsigned int size, T initvalue)
{
	Vector();

	if(size >= getLength())
	{
		m_resize(size + 5);
	}

	//Set the initial value of new elements
	m_initValue = initvalue;

	//Fill the vector with the value
	fill();
}

template<typename T>
CGDK::core::Vector<T>::Vector(std::vector<T> stdvec)
{
	Vector();

	for(unsigned int i = 0; i < stdvec.size(); i++)
	{
		add(stdvec[i]);
	}
}

template<typename T>
CGDK::core::Vector<T>::~Vector()
{
}

template<typename T>
CGDK::core::Vector<T> CGDK::core::Vector<T>::getSubVector(unsigned int start, unsigned int length)
{
	if(m_isValidPos(start))
	{
		CGDK_ASSERT((start + length) <= getSize(), "Subvector out of bounds");

		CGDK::core::Vector<T> vec;

		for(int i = start; i < (start + length -1); i++)
		{
			vec.add(get(i));
		}

		return vec;
	}
}

template<typename T>
void CGDK::core::Vector<T>::setMaximumSize(unsigned int max)
{
	m_maxSize = max;
}

template<typename T>
unsigned int CGDK::core::Vector<T>::getMaximumSize()
{
	return m_maxSize;
}

template<typename T>
template<typename T2>
CGDK::core::Vector<T> CGDK::core::Vector<T>::operator+(T2 val)
{
	CGDK::core::Vector<T> vec(getLength());

	for(int i = 0; i < getLength(); i++)
	{
		vec.add(get(i) + val);
	}

	return vec;
}

template<typename T>
template<typename T2>
CGDK::core::Vector<T>& CGDK::core::Vector<T>::operator+=(T2 val)
{
	for(int i = 0; i < getLength(); i++)
	{
		set(i, get(i) + val);
	}

	return self;
}

template<typename T>
template<typename T2>
CGDK::core::Vector<T> CGDK::core::Vector<T>::operator-(T2 val)
{
	CGDK::core::Vector<T> vec(getLength());

	for(int i = 0; i < getLength(); i++)
	{
		vec.set(i, get(i) - val);
	}

	return vec;
}

template<typename T>
template<typename T2>
CGDK::core::Vector<T>& CGDK::core::Vector<T>::operator-=(T2 val)
{
	for(int i = 0; i < getLength(); i++)
	{
		set(i, get(i) - val);
	}

	return self;
}

template<typename T>
template<typename T2>
CGDK::core::Vector<T> CGDK::core::Vector<T>::operator*(T2 val)
{
	CGDK::core::Vector<T> vec(getLength());

	for(int i = 0; i < getLength(); i++)
	{
		vec.set(i, get(i) * val);
	}

	return vec;
}

template<typename T>
template<typename T2>
CGDK::core::Vector<T>& CGDK::core::Vector<T>::operator*=(T2 val)
{
	for(int i = 0; i < getLength(); i++)
	{
		set(i, get(i) * val);
	}

	return self;
}

template<typename T>
template<typename T2>
CGDK::core::Vector<T> CGDK::core::Vector<T>::operator/(T2 val)
{
	CGDK::core::Vector<T> vec(getLength());

	for(int i = 0; i < getLength(); i++)
	{
		vec.set(i, get(i) / val);
	}

	return vec;
}

template<typename T>
template<typename T2>
CGDK::core::Vector<T>& CGDK::core::Vector<T>::operator/=(T2 val)
{
	for(int i = 0; i < getLength(); i++)
	{
		set(i, get(i) / val);
	}

	return self;
}

template<typename T>
template<typename T2>
CGDK::core::Vector<T> CGDK::core::Vector<T>::operator%(T2 val)
{
	CGDK::core::Vector<T> vec(getLength());

	for(int i = 0; i < getLength(); i++)
	{
		vec.set(i, get(i) % val);
	}

	return vec;
}

template<typename T>
template<typename T2>
CGDK::core::Vector<T>& CGDK::core::Vector<T>::operator%=(T2 val)
{
	for(int i = 0; i < getLength(); i++)
	{
		set(i, get(i) + val);
	}

	return self;
}

template<typename T>
bool CGDK::core::Vector<T>::operator<(CGDK::core::Vector<T> vec)
{
	bool smaller = true;

	for(int i = 0; i < m_getLongestSize(vec); i++)
	{
		if(!(get(i) < vec[i]))
		{
			smaller = false;
			break;
		}
	}

	return smaller;
}

template<typename T>
bool CGDK::core::Vector<T>::operator<=(CGDK::core::Vector<T> vec)
{
	bool smaller_or_eq = true;

	for(int i = 0; i < m_getLongestSize(vec); i++)
	{
		if(!(get(i) <= vec[i]))
		{
			smaller_or_eq = false;
			break;
		}
	}

	return smaller_or_eq;
}

template<typename T>
bool CGDK::core::Vector<T>::operator>(CGDK::core::Vector<T> vec)
{
	bool larger = true;

	for(int i = 0; i < m_getLongestSize(vec); i++)
	{
		if(!(get(i) > vec[i]))
		{
			larger = false;
			break;
		}
	}

	return larger;
}

template<typename T>
bool CGDK::core::Vector<T>::operator>=(CGDK::core::Vector<T> vec)
{
	bool larger_or_eq = true;

	for(int i = 0; i < m_getLongestSize(vec); i++)
	{
		if(!(get(i) >= vec[i]))
		{
			larger_or_eq = false;
			break;
		}
	}

	return larger_or_eq;
}

template<typename T>
CGDK::core::Vector<T> CGDK::core::Vector<T>::operator++()
{
	for(int i = 0; i < getLength(); i++)
	{
		set(i, get(i) + static_cast<T>(1));
	}

	return self;
}

template<typename T>
CGDK::core::Vector<T> CGDK::core::Vector<T>::operator++(int)
{
	CGDK::core::Vector<T> oldvec(this);

	for(int i = 0; i < getLength(); i++)
	{
		set(i, get(i) + static_cast<T>(1));
	}

	return oldvec;
}

template<typename T>
CGDK::core::Vector<T> CGDK::core::Vector<T>::operator--()
{
	for(int i = 0; i < getLength(); i++)
	{
		set(i, get(i) - static_cast<T>(1));
	}

	return self;
}

template<typename T>
CGDK::core::Vector<T> CGDK::core::Vector<T>::operator--(int)
{
	CGDK::core::Vector<T> oldvec(this);

	for(int i = 0; i < getLength(); i++)
	{
		set(i, get(i) + static_cast<T>(1));
	}

	return oldvec;
}

template<typename T>
void CGDK::core::Vector<T>::add(T element)
{
	CGDK_ASSERT(m_maxSize != 0 && getLength() < m_maxSize, "Maximum element count exceeded");
	
	m_pushBack(element);
}

template<typename T>
void CGDK::core::Vector<T>::add(CGDK::core::Vector<T> vector)
{
	for(int i = 0; i < vector.getLength(); i++)
	{
		add(vector[i]);
	}
}

template<typename T>
void CGDK::core::Vector<T>::add(std::vector<T> vector)
{
	for(int i = 0; i < vector.size(); i++)
	{
		add(vector[i]);
	}
}

template<typename T>
void CGDK::core::Vector<T>::unique()
{
	CGDK::core::Vector<T> uniquevec;

	for(int i = 0; i < getSize(); i++)
	{
		if(!uniquevec.contains(get(i)))
		{
			uniquevec.add(get(i));
		}
	}

	m_vector = uniquevec.getStdVector();
}

template<typename T>
real CGDK::core::Vector<T>::getSum()
{
	real sum = static_cast<T>(0);

	for(int i = 0; i < getSize(); i++)
	{
		sum += get(i);
	}

	return sum;
}

template<typename T>
real CGDK::core::Vector<T>::getAverage()
{
	return static_cast<real>(getSum() / getSize());
}

template<typename T>
real CGDK::core::Vector<T>::getMedian()
{
	if(getSize() % 2 == 0)
	{
		return static_cast<real>((get(static_cast<int>(getSize() / 2))) / (get(static_cast<int>(getSize / 2) + 1)));
	}
	else
	{
		return static_cast<real>(get(static_cast<int>(getSize() / 2) + 1));
	}
}

template<typename T>
real CGDK::core::Vector<T>::getDotProduct(CGDK::core::Vector<T> vec)
{
	CGDK_ASSERT(getSize() == vec.getSize(), "Size does not match");

	real dot = 0;

	for(int i = 0; i < getSize(); i++)
	{
		dot += (get(i) * vec.get(i));
	}
}



[C++] Unresolved external

16 January 2010 - 04:05 AM

I'm having a problem with unresolved external symbols in a class which i can't manage to fix. I have a class splitted up into a header file, and a source file. And here they are: MemoryObject.hpp
#pragma once
#include <string>
#include <list>

#define CGDK_T_TYPE typeid(T).name()
#define CGDK_GETMEMORYSIZE_METHOD virtual inline unsigned long getMemorySize() {return sizeof(*this);}

namespace CGDK
{
	namespace core
	{
		class MemoryObject
		{
		private:
			static std::list<MemoryObject*> m_liveObjects;
			static std::list<MemoryObject*> m_deadObjects;
			long m_referenceCount;
			unsigned long m_listPosition;

#ifndef CGDK_RELEASE
			std::string m_fullName;
#endif

			static unsigned long m_fullMemoryUsage;

		protected:
			MemoryObject();
			virtual ~MemoryObject();

		public:
			inline void addReference();
			inline void release();
			static void collectGarbage();
			static void collectRemaining();
			static unsigned long getObjectCount();
			virtual unsigned long getMemorySize()=0;

#ifndef CGDK_RELEASE
			void setDebugName(std::string name, std::string type);
			void setDebugName(std::string name);
			std::string getDebugName();
#endif
		};
	}
}



MemoryObject.hpp
#include "MemoryObject.hpp"

std::list<CGDK::core::MemoryObject*> CGDK::core::MemoryObject::m_liveObjects;
std::list<CGDK::core::MemoryObject*> CGDK::core::MemoryObject::m_deadObjects;

CGDK::core::MemoryObject::MemoryObject()
{
	m_liveObjects.push_back(this);

	//Set the initial reference count to 0
	m_referenceCount = 0;
}

CGDK::core::MemoryObject::~MemoryObject()
{
}

void CGDK::core::MemoryObject::addReference()
{
	m_referenceCount++;
}

void CGDK::core::MemoryObject::release()
{
	--m_referenceCount;

	if(m_referenceCount <= 0)
	{
		m_liveObjects.remove(this);
		m_deadObjects.push_back(this);
	}
}

void CGDK::core::MemoryObject::collectGarbage()
{
	for(std::list<MemoryObject*>::iterator it = m_deadObjects.begin(); it != m_deadObjects.end(); it++)
	{
		MemoryObject *o = (*it);
		delete(o);
		it++;
	}

	m_deadObjects.clear();
}

void CGDK::core::MemoryObject::collectRemaining()
{
	collectGarbage();

	for(std::list<MemoryObject*>::iterator it = m_liveObjects.begin(); it != m_liveObjects.end(); it++)
	{
		CGDK::core::MemoryObject *o=(*it);
		delete o;
	}

	m_liveObjects.clear();
}

unsigned long CGDK::core::MemoryObject::getObjectCount()
{
	return static_cast<unsigned long>(m_liveObjects.size()) - 1;
}

void CGDK::core::MemoryObject::setDebugName(std::string name, std::string type)
{
	m_fullName = name.append("<").append(type).append(">");
}

void CGDK::core::MemoryObject::setDebugName(std::string name)
{
	m_fullName = name;
}

std::string CGDK::core::MemoryObject::getDebugName()
{
	return m_fullName;
}



The code that causes the problem is this: main.cpp
#include "CGDK.hpp"

using namespace std;
using namespace CGDK::core;

int main(int argc, char *argv[])
{
	MemoryPointer<Vector<int>> v;

	

	return 0;
}



MemoryPointer is a templated class defines as such: MemoryPointer.hpp
#pragma once

#include "_stdlibrary.hpp"

namespace CGDK
{
	namespace core
	{
		template<typename T>
		class MemoryPointer
		{
		protected:
			T* m_object;

		public:
			MemoryPointer();
			MemoryPointer(T* obj);
			MemoryPointer(const MemoryPointer<T> &pointer);
			
			~MemoryPointer();

			inline void operator=(T* obj);
			inline void operator=(const MemoryPointer<T> &pointer);

			//Reference access
			inline T& operator *() const;

			//Pointer access
			inline T* operator ->() const;

			//Type converting
			inline operator T*() const;

			inline bool operator !() const;
			inline bool operator ==(const CGDK::core::MemoryPointer<T> &pointer) const;
			inline bool operator ==(const T* obj) const;

			inline bool isValid() const;
		};
	}
}

template<typename T>
CGDK::core::MemoryPointer<T>::MemoryPointer()
{
	m_object = 0;
}

template<typename T>
CGDK::core::MemoryPointer<T>::MemoryPointer(T *obj)
{
	m_object = 0;
	*this = obj;
}

template<typename T>
CGDK::core::MemoryPointer<T>::MemoryPointer(const CGDK::core::MemoryPointer<T> &pointer)
{
	m_object = 0;
	*this = p;
}

template<typename T>
CGDK::core::MemoryPointer<T>::~MemoryPointer()
{
	if(m_object)
	{
		m_object->release();
	}
}

template<typename T>
void CGDK::core::MemoryPointer<T>::operator=(T *obj)
{
	//Decrement the reference counter if the is an object
	if(m_object)
	{
		m_object->release();
	}

	m_object = obj;

	//Increment the reference counter...
	if(m_object)
	{
		m_object->addReference();
	}
}

template<typename T>
void CGDK::core::MemoryPointer<T>::operator=(const CGDK::core::MemoryPointer<T> &pointer)
{
	//Decrement the reference counter if the is an object
	if(m_object)
	{
		m_object->release();
	}

	m_object = pointer.m_object;

	//Increment the reference counter...
	if(m_object)
	{
		m_object->addReference();
	}
}

template<typename T>
T& CGDK::core::MemoryPointer<T>::operator*() const
{
	CGDK_ASSERT(obj != 0, "Tried to * on a NULL smart pointer");

	return *m_object;
}

template<typename T>
T* CGDK::core::MemoryPointer<T>::operator->() const
{
	CGDK_ASSERT(obj != 0, "Tried to -> on a NULL smart pointer");

	return m_object;
}

template<typename T>
CGDK::core::MemoryPointer<T>::operator T*() const
{
	return obj;
}

template<typename T>
bool CGDK::core::MemoryPointer<T>::operator !() const
{
	return !(m_object);
}

template<typename T>
bool CGDK::core::MemoryPointer<T>::operator ==(const CGDK::core::MemoryPointer<T> &pointer) const
{
	return (m_object == pointer.m_object);
}

template<typename T>
bool CGDK::core::MemoryPointer<T>::operator ==(const T *obj) const
{
	return (m_object == obj);
}



If you're wondering, _stdlibrary.hpp includes some standard C++ headers, some project specific and holds some defines. The full error i'm getting is this:
Error	1	error LNK2019: unresolved external symbol "public: void __thiscall CGDK::core::MemoryObject::release(void)"
 (?release@MemoryObject@core@CGDK@@QAEXXZ) referenced in function 
"public: __thiscall CGDK::core::MemoryPointer<class CGDK::core::Vector<int> >::~MemoryPointer<class CGDK::core::Vector<int> >(void)"
(??1?$MemoryPointer@V?$Vector@H@core@CGDK@@@core@CGDK@@QAE@XZ)	main.obj	


I'm using Visual Studio, and all those files are in the same project so everything should be automatically linked in where it should. MemoryObject and MemoryPointer are based on IMMPointer and IMMObject from the Enginuity "tutorials" here on GameDev.

PARTNERS