Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Iterator Conversion problem?

$
0
0
I'm not sure what is the problem, as I don't see any syntax errors, and I have no idea what this long ass list of stuff means, but if you are willing to read this and help me understand what it means I'd appreciate it. I occasionally compile to see if anything will come out wrong and this is what I got.

Here's the code it concerns:
QuadTree.h
#pragma once

#include "stdafx.h"
#include "VisibleGameObject.h"

enum Quadrant { NONE = 0, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, };
enum NodeType { BRANCH = 99, LEAF };

class QuadTreeNode;

typedef std::set<VisibleGameObject*> ObjectSet;
typedef std::set<QuadTreeNode*> NodeSet;

class QuadTree
{
public:
	QuadTree( float width, float height, unsigned int maxObjects );
	QuadTreeNode* CreateNode( float x, float y, float w, float h, Quadrant quad, QuadTreeNode* parent = NULL );
	void Divide( QuadTreeNode* parent );
	void TransferListDown( QuadTreeNode* parent, QuadTreeNode* child );
	void TransferListUp( QuadTreeNode* parent, QuadTreeNode* child );
	bool CheckNodeBounds( VisibleGameObject* object, QuadTreeNode* node );
	void Update( float elapsedTime );

protected:
	float _width;
	float _height;
	unsigned int _maxObjects;
	ObjectSet CollideList;
	NodeSet NodeList;
};




QuadTree.cpp
#include "stdafx.h"
#include "Quadtree.h"
#include "QuadTreeNode.h"


QuadTree::QuadTree( float width, float height, unsigned int maxObjects ) : _width( width ),
	_height( height ), _maxObjects( maxObjects )
{
}

QuadTreeNode* QuadTree::CreateNode( float x, float y, float w, float h, Quadrant quad, QuadTreeNode* parent )
{
	if( parent != NULL )
	{
		if( parent->_nodeType == NodeType::BRANCH )
		{
			QuadTreeNode* newNode = new QuadTreeNode( x, y, w, h, quad, NodeType::LEAF, parent );
			return newNode;
		}

		if( parent->_nodeType == NodeType::LEAF )
		{
			QuadTreeNode* newNode = new QuadTreeNode( x, y, w, h, quad, NodeType::LEAF, parent );
			parent->_nodeType = NodeType::BRANCH;
			return newNode;
		}
	}

	else
	{
		QuadTreeNode* newNode = new QuadTreeNode( x, y, w, h, quad, NodeType::BRANCH, NULL );
		return newNode;
	}	
}

void QuadTree::Divide( QuadTreeNode* parent )
{
	// Get the parent node width, height, x and y
	float w = parent->_width;
	float h = parent->_height;
	float x = parent->_posX;
	float y = parent->_posY;

	// Top Left
	QuadTreeNode* child =  CreateNode( x, y, w * 0.5f, h * 0.5f, Quadrant::TOP_LEFT, parent );
	bool exists = NodeList.find( child ) != NodeList.end();

	if( !exists )
	{
		NodeList.insert( child );
		TransferListDown( parent, child );
	}

	else
		delete child;

	// Top Right
	child = CreateNode( x + ( w * 0.5f ), y, w * 0.5f, h * 0.5f, Quadrant::TOP_RIGHT, parent );
	exists = NodeList.find( child ) != NodeList.end();

	if( !exists )
	{
		NodeList.insert( child );
		TransferListDown( parent, child );
	}

	else
		delete child;

	// Bottom Left
	child = CreateNode( x, y + ( h * 0.5f ), w * 0.5f, h * 0.5f, Quadrant::BOTTOM_LEFT, parent );
	exists = NodeList.find( child ) != NodeList.end();

	if( !exists )
	{
		NodeList.insert( child );
		TransferListDown( parent, child );
	}

	else
		delete child;

	// Bottom Right
	child = CreateNode( x + ( w * 0.5f ), y + ( h * 0.5f ), w * 0.5f, h * 0.5f, Quadrant::BOTTOM_RIGHT, parent );
	exists = NodeList.find( child ) != NodeList.end();

	if( !exists )
	{
		NodeList.insert( child );
		TransferListDown( parent, child );
	}

	else
		delete child;
}

void QuadTree::TransferListDown( QuadTreeNode* parent, QuadTreeNode* child )
{
	// This function will transfer all objects from the parent list to the children's list
	for( ObjectSet::iterator x = parent->_CollideList.begin(); x != parent->_CollideList.end(); x++ )
	{
		if( CheckNodeBounds( (*x), child ) )
		{
			child->_CollideList.insert( x );
			parent->_CollideList.erase( x );
		}

		else
			continue;
	}
}

void QuadTree::TransferListUp( QuadTreeNode* parent, QuadTreeNode* child )
{
	
}

bool QuadTree::CheckNodeBounds( VisibleGameObject* object, QuadTreeNode* node )
{
	sf::Rect<float> rect;
	rect.Left = node->_posX;
	rect.Right = node->_posX + node->_width;
	rect.Top = node->_posY;
	rect.Bottom = node->_posY + node->_height;

	return rect.Intersects( object->GetBoundingRect(), &rect );
}




Here's the Error:

Quote

>c:\program files\microsoft visual studio 10.0\vc\include\xmemory(208): error C2440: 'initializing' : cannot convert from 'std::_Tree_const_iterator<_Mytree>' to 'VisibleGameObject *'
1> with
1> [
1> _Mytree=std::_Tree_val<std::_Tset_traits<VisibleGameObject *,std::less<VisibleGameObject *>,std::allocator<VisibleGameObject *>,false>>
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1> c:\program files\microsoft visual studio 10.0\vc\include\xmemory(280) : see reference to function template instantiation 'void std::allocator<_Ty>::construct<std::_Tree_const_iterator<_Mytree>&>(VisibleGameObject **,_Other)' being compiled
1> with
1> [
1> _Ty=VisibleGameObject *,
1> _Mytree=std::_Tree_val<std::_Tset_traits<VisibleGameObject *,std::less<VisibleGameObject *>,std::allocator<VisibleGameObject *>,false>>,
1> _Other=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<VisibleGameObject *,std::less<VisibleGameObject *>,std::allocator<VisibleGameObject *>,false>>> &
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\xtree(592) : see reference to function template instantiation 'void std::_Cons_val<std::allocator<_Ty>,_Ty,std::_Tree_const_iterator<_Mytree>&>(_Alloc &,_Ty1 *,_Ty2)' being compiled
1> with
1> [
1> _Ty=VisibleGameObject *,
1> _Mytree=std::_Tree_val<std::_Tset_traits<VisibleGameObject *,std::less<VisibleGameObject *>,std::allocator<VisibleGameObject *>,false>>,
1> _Alloc=std::allocator<VisibleGameObject *>,
1> _Ty1=VisibleGameObject *,
1> _Ty2=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<VisibleGameObject *,std::less<VisibleGameObject *>,std::allocator<VisibleGameObject *>,false>>> &
1> ]
1> c:\program files\microsoft visual studio 10.0\vc\include\xtree(755) : see reference to function template instantiation 'std::_Tree_nod<_Traits>::_Node *std::_Tree_val<_Traits>::_Buynode<std::_Tree_const_iterator<_Mytree>&>(_Valty)' being compiled
1> with
1> [
1> _Traits=std::_Tset_traits<VisibleGameObject *,std::less<VisibleGameObject *>,std::allocator<VisibleGameObject *>,false>,
1> _Mytree=std::_Tree_val<std::_Tset_traits<VisibleGameObject *,std::less<VisibleGameObject *>,std::allocator<VisibleGameObject *>,false>>,
1> _Valty=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<VisibleGameObject *,std::less<VisibleGameObject *>,std::allocator<VisibleGameObject *>,false>>> &
1> ]
1> f:\users\GC\documents\visual studio 2010\projects\pang tutorial\pang tutorial\quadtree.cpp(104) : see reference to function template instantiation 'std::pair<_Ty1,_Ty2> std::_Tree<_Traits>::insert<std::_Tree_const_iterator<_Mytree>&>(_Valty)' being compiled
1> with
1> [
1> _Ty1=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<VisibleGameObject *,std::less<VisibleGameObject *>,std::allocator<VisibleGameObject *>,false>>>,
1> _Ty2=bool,
1> _Traits=std::_Tset_traits<VisibleGameObject *,std::less<VisibleGameObject *>,std::allocator<VisibleGameObject *>,false>,
1> _Mytree=std::_Tree_val<std::_Tset_traits<VisibleGameObject *,std::less<VisibleGameObject *>,std::allocator<VisibleGameObject *>,false>>,
1> _Valty=std::_Tree_const_iterator<std::_Tree_val<std::_Tset_traits<VisibleGameObject *,std::less<VisibleGameObject *>,std::allocator<VisibleGameObject *>,false>>> &
1> ]


From what I gather there is something wrong with the iterator I used to iterate through my ObjectSet. I've used this technique before in a different project, but for some reason I get this long winded error that I lack the knowledge to make heads or tails of. Either that or there is a problem with the call
CheckNodeBounds( (*x), child );



On QuadTree.cpp line 102, if so, I can't see why there is a problem, as I have done this before as well and it worked.

Viewing all articles
Browse latest Browse all 51036

Trending Articles