5 Replies - 281 Views - Last Post: 12 December 2012 - 11:26 PM Rate Topic: -----

#1 GryphonClaws  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 37
  • Joined: 09-December 12

Why am I getting this error? (Un)resolved External Symbol

Posted 12 December 2012 - 10:05 PM

Hello D.I.C.ers.

I've encountered this error enough to know that it usually means a static object wasn't defined or initialized but I'm pretty sure I've done that. Here's the file where it keeps screwing up. Trying to test my Quadtree and can't figure out why it won't accept my code.

The error is:

Quote

1>Game.obj : error LNK2001: unresolved external symbol "public: static class CQuadTreeNode * Game::ScreenNode" (?ScreenNode@Game@@2PAVCQuadTreeNode@@A)
1>F:\Users\Dark Glitch\Documents\Visual Studio 2010\Projects\Pang Tutorial\Debug\Pang Tutorial.exe : fatal error LNK1120: 1 unresolved externals


#include "stdafx.h"
#include "Game.h"
#include "Main_Menu.h"
#include "SplashScreen.h"

CQuadTreeNode* ScreenNode = new CQuadTreeNode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, NULL );

void Game::Start()
{
	if( _gameState != Uninitialized )
	{
		return;
	}

	_mainwindow.Create( sf::VideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 32 ), "");

	MainPlayerEntity* _player1 = new MainPlayerEntity();
	_player1->Load( "TestPlayer" );
	_player1->SetPosition( 600, 700 );

	ScreenNode->AddObject( _player1 );
	

	PlayerPaddle* _Test = new PlayerPaddle();
	_Test->SetPosition( 100, 700 );

	ScreenNode->AddObject( _Test );
	
	_gameState = Game::ShowingSplash;

	while( !IsExiting() )
	{
		GameLoop();
	}

	_mainwindow.Close();
}

const sf::Input& Game::GetInput() 
{
	return _mainwindow.GetInput();
}

bool Game::IsExiting()
{
	if( _gameState == Game::Exiting )
	{
		return true;
	}

	else
		return false;
}

sf::RenderWindow& Game::GetWindow()
{
	return _mainWindow;
}

void Game::GameLoop()
{
	sf::Event currentEvent;
	_mainwindow.GetEvent( currentEvent );

	switch( _gameState )
	{
	case Game::ShowingMenu:
		{
			ShowMenu();
			break;
		}
	
	case Game::ShowingSplash:
		{
			ShowSplashScreen();
			break;
		}

	case Game::Playing:
		{
			_mainwindow.Clear( sf::Color( 0, 0, 0 ) );
			
			ScreenNode->Update( _mainwindow.GetFrameTime() );

			_mainwindow.Display();
				
			if( currentEvent.Type == sf::Event::Closed )
			{
				_gameState = Game::Exiting;
			}

			if( currentEvent.Type == sf::Event::KeyPressed )
			{
				if( currentEvent.Key.Code == sf::Key::Escape ) 
				{
					ShowMenu();
				}
			}
			break;
		}

	default:
		{
			break;
		}
	}
}

void Game::ShowSplashScreen()
{
	SplashScreen splashScreen;
	splashScreen.Show( _mainWindow );
	_gameState = Game::ShowingMenu;
}

void Game::ShowMenu()
{
	Main_Menu mainMenu;
	Main_Menu::MenuResult result = mainMenu.Show( _mainWindow );

	switch( result )
	{
	case Main_Menu::Exit:
		_gameState = Game::Exiting;
		break;

	case Main_Menu::Play:
		_gameState = Game::Playing;
		break;
	}
}

// Static Variable Instances
Game::GameState Game::_gameState = Uninitialized;
sf::RenderWindow Game::_mainWindow;
CQuadTreeNode* ScreenNode = new CQuadTreeNode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, NULL );



Help is appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Why am I getting this error? (Un)resolved External Symbol

#2 DoNotWant  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 59
  • Joined: 03-November 11

Re: Why am I getting this error? (Un)resolved External Symbol

Posted 12 December 2012 - 10:25 PM

Where is the code for CQuadTreeNode? Is it in any of the #included files? Are you using the right amount of arguments? Have you actually implemented the constructor?
Was This Post Helpful? 0
  • +
  • -

#3 GryphonClaws  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 37
  • Joined: 09-December 12

Re: Why am I getting this error? (Un)resolved External Symbol

Posted 12 December 2012 - 10:48 PM

Quadtree.h
#pragma once

#include <cstdlib>
#include "VisibleGameObject.h"
#include "Bullet.h"
#include <set>


const int MAX_OBJECTS = 5;

class CQuadTreeNode
{
public:
	CQuadTreeNode( long lowerRightX, long lowerRightY, long width, long height, CQuadTreeNode* parent = NULL );
	virtual ~CQuadTreeNode();

	int SubDivide();
	int AddObject( VisibleGameObject* object );
	int GetDimensions( float* lrx, float* lry, float* width, float* height );
	int GetObjectCount();
	void Update( float elapsedTime );
	bool GetMainTarget();
	bool GetCamera();
	bool CheckCollision( const VisibleGameObject* object1, const VisibleGameObject* object2 );

private:
	float LowerRightX;
	float LowerRightY;
	float Width;
	float Height;

	CQuadTreeNode** SubNodes;
	CQuadTreeNode* ParentNode;
	CQuadTreeNode* MainNode;

	void SearchParentNode();
	
	// This will store the objects added to our node
	typedef std::set<VisibleGameObject*> ObjectSet;
	ObjectSet CollideList;
	ObjectSet::iterator it;
	ObjectSet::iterator *ptr_player;
	ObjectSet::iterator *ptr_camera;
};

enum Quadrant
{
	UpperLeft = 0,
	UpperRight,
	LowerLeft,
	LowerRight
};



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

CQuadTreeNode::CQuadTreeNode( long lowerRightX, long lowerRightY, long width, long height, CQuadTreeNode* parent ) : 
							 LowerRightX( lowerRightX ), LowerRightY( lowerRightY ), Width( width ),
								 Height( height ), SubNodes( NULL ), ptr_player( NULL ), ptr_camera( NULL ),
									ParentNode( parent ), MainNode( NULL ), it( NULL, NULL )
{
	if( ParentNode == NULL )
	{
		// If this Node has no parent node, then this is the FIRST node.
		MainNode = this;
	}
}


CQuadTreeNode::~CQuadTreeNode()
{
	if (!SubNodes) 
	{
      it = CollideList.begin();

      while (it != CollideList.end() ) 
	  {
		  delete (*it);      
         it++;
      }

      CollideList.clear();
   }
   else {
      for (int i = 0; i < 4; i++) {
         delete SubNodes[i];
      }
      ::free(SubNodes);
   }
}

int CQuadTreeNode::SubDivide()
{
	int result = 0;
	if( !SubNodes )
	{
		// We have no subnodes so this must be a leaf node
		// Create 4 children nodes will be its children
		

		SubNodes = ( CQuadTreeNode** )::malloc( 4 * sizeof( CQuadTreeNode* ) );

		ParentNode = this;

		SubNodes[ UpperLeft ] = new CQuadTreeNode( LowerRightX * 0.5, LowerRightY *0.5, Width * 0.5, Height * 0.5, ParentNode );
		SubNodes[ UpperRight ] = new CQuadTreeNode( LowerRightX, LowerRightY * 0.5, Width * 0.5, Height * 0.5, ParentNode );
		SubNodes[ LowerLeft ] = new CQuadTreeNode( LowerRightX * 0.5, LowerRightY, Width * 0.5, Height * 0.5, ParentNode );
		SubNodes[ LowerRight ] = new CQuadTreeNode( LowerRightX, LowerRightY, Width * 0.5, Height * 0.5, ParentNode  );
	}

	else
	{
		// This node already has children so it is a branch node
		// All we do is forward this call to our sub nodes and tell them to subdivide
		for( int x = 0; x < 4 && result == 0; x++ )
		{
			result = SubNodes[ x ]->SubDivide();
		}
	}
	
	return result;
}

int CQuadTreeNode::AddObject( VisibleGameObject* object )
{
	int result = 0;

	// If this node has sub nodes figure out which sub node this object belongs in
	// and add it, otherwise just add it to the list
	if( !SubNodes )
	{
		// If no sub nodes, this is a leaf node
		std::pair<ObjectSet::iterator, bool> newInsertion;

		// Make sure this Entity isn't in the list already
		if( CollideList.find( object ) == CollideList.end() )
		{
			newInsertion = CollideList.insert( object );
		}
	}

	else
	{
		// Dimesions
		float lrx, lry, w, h;

		for( int i = 0; i < 4; i++)
		{
			SubNodes[ i ]->GetDimensions( &lrx, &lry, &w, &h );
			
			// 1 is the Quadtree, 2 is the Object
			float left1, right1, bottom1, top1;
			float left2, right2, bottom2, top2;
			
			left1 = lrx - w;
			right1 = lrx;
			top1 = lry - h;
			bottom1 = lry;

			left2 = object->GetPosition().x;
			right2 = object->GetPosition().x + object->GetWidth();
			top2 = object->GetPosition().y + object->GetHeight();
			bottom2 = object->GetPosition().y;

			if( bottom2 > top1 || top2 < bottom1 || left2 < right1 || right2 > left1 )
			{
				SubNodes[ i ]->AddObject( object );
			}

			else
			{
				continue;
			}

		}
	}

	return result;
}

int CQuadTreeNode::GetDimensions( float* lrx, float* lry, float* width, float* height )
{
	lrx = &LowerRightX;
	lry = &LowerRightY;
	width = &Width;
	height = &Height;

	return 0;
}

void CQuadTreeNode::Update( float elapsedTime )
{
	float lrx, lry, w, h;

	// 1 is the Quadtree, 2 is the Object
	float left1, right1, bottom1, top1;
	float left2, right2, bottom2, top2;

	// Check Object count. If higher than the limit, subdivide
	if( !SubNodes )
	{
		// This loop will check if objects are alive first, removing them if they are not.
		for( it = CollideList.begin(); it != CollideList.end(); it++ )
		{
			if( !(*it)->IsAlive() )
			{
				CollideList.erase( it );
			}
		}

		if( GetObjectCount() > MAX_OBJECTS )
		{
			SubDivide();
		}
	}

	else
	{
		for( int x = 0; x != 4; x++ )
		{
			// This loop will check if objects are alive first, removing them if they are not.
			for( it = SubNodes[ x ]->CollideList.begin(); it != SubNodes[ x ]->CollideList.end(); it++ )
			{
				if( !(*it)->IsAlive() )
				{
					CollideList.erase( it );
				}
			}

			if( SubNodes[ x ]->GetObjectCount() > MAX_OBJECTS )
			{
				SubDivide();
			}
		}
	}

	if( !SubNodes )
	{  
		// If Leaf...
		if( !GetMainTarget() )
		{
			// If the camera isn't in this node then exit immediately.
			return;
		}

		else
		{
			// Update each object first
			for( it = CollideList.begin(); it != CollideList.end(); it++ )
			{
				(*it)->Update( elapsedTime );
		
				this->GetDimensions( &lrx, &lry, &w, &h );
			
				left1 = lrx - w;
				right1 = lrx;
				top1 = lry - h;
				bottom1 = lry;

				left2 = (*it)->GetPosition().x;
				right2 = (*it)->GetPosition().x + (*it)->GetWidth();
				top2 = (*it)->GetPosition().y + (*it)->GetHeight();
				bottom2 = (*it)->GetPosition().y;

				if( bottom2 > top1 || top2 < bottom1 || left2 < right1 || right2 > left1 )
				{
					// If the object is still within bounds, keep going
					continue;
				}

				else
				{
					// If not within the bounds then remove this object from the list
					CollideList.erase( it );

					// And THEN add it back to the main node so it can get put in the right place
					MainNode->AddObject( (*it) );
				} 
			}		
		}

		// Now that all updates are done, check collisions
		for( it = CollideList.begin(); it != CollideList.end(); it++ )
		{
			if( ptr_player != NULL )
			{
				if( *ptr_player == it || it == *ptr_camera )
				{
					// If this is the player or the camera don't check collision.
					continue;
				}
				(**ptr_player)->CollisionResponse( (*it) );
			} 
		}
	}

	else
	{
		// If this is a  Branch...
		for( int x = 0; x < 4; x++ )
		{
			if( !SubNodes[ x ]->GetMainTarget() )
			{
				if( x == 3 && !SubNodes[ 3 ]->GetMainTarget() )
				{
					// If the last node doesn't have the main target, then exit this function
					return;
				}

				continue;
			}

			else
			{
				// If the main target is in this node, then update all objects
				for( it = SubNodes[ x ]->CollideList.begin();
					 it != SubNodes[ x ]->CollideList.end();
					 it++ )
				{
					(*it)->Update( elapsedTime );

					// Check if object is still in this node
					SubNodes[ x ]->GetDimensions( &lrx, &lry, &w, &h );
			
					left1 = lrx - w;
					right1 = lrx;
					top1 = lry - h;
					bottom1 = lry;

					left2 = (*it)->GetPosition().x;
					right2 = (*it)->GetPosition().x + (*it)->GetWidth();
					top2 = (*it)->GetPosition().y + (*it)->GetHeight();
					bottom2 = (*it)->GetPosition().y;

					if( bottom2 > top1 || top2 < bottom1 || left2 < right1 || right2 > left1 )
					{
						// If the object is still within bounds, keep going
						continue;
					}

					else
					{
						// If not within the bounds then remove this object from the list
						SubNodes[ x ]->CollideList.erase( it );

						// And THEN add it back to the main node so it can get put in the right place
						MainNode->AddObject( (*it) );
					}
				}
			}

			// Now that all updates are done, check collisions
			for( it = SubNodes[ x ]->CollideList.begin(); it != SubNodes[ x ]->CollideList.end(); it++ )
			{
				if( ptr_player != NULL )
				{
					if( *ptr_player == it || it == *ptr_camera )
					{
						// If this is the player or the camera don't check collision.
						continue;
					}

					if( CheckCollision( (**ptr_player), (*it) ) )
					{
						(**ptr_player)->CollisionResponse( (*it) );
					}
				} 
			}
		}
	}

	// Now that all updates are done, now we check collisions
}

bool CQuadTreeNode::GetMainTarget()
{
	// This function searches for the player and camera objects in a node
	for( it = CollideList.begin(); it != CollideList.end(); it++ )
	{
		switch( (*it)->GetType() )
		{
			case VisibleGameObject::PLAYER:
				ptr_player = std::addressof( it );
				break;

			case VisibleGameObject::CAMERA:
				ptr_camera = std::addressof( it );
				break;

			default:
				break;
		}
	}

	if ( ptr_camera != NULL )
	{
		return true;
	}

	else
	{
		return false;
	}
}

inline int CQuadTreeNode::GetObjectCount()
{
	// Pretty self-explanitory. Finds how many objects are currently in a node
	int count = 0;

	for( it = CollideList.begin(); it != CollideList.end(); it++ )
	{
		count++;
	}

	return count;
}

void CQuadTreeNode::SearchParentNode()
{

	if( ParentNode != NULL )
	{

	}
}

bool CQuadTreeNode::CheckCollision( const VisibleGameObject* object, const VisibleGameObject* object2 )
{
	sf::Rect<float> objRect = object->GetBoundingRect();

	return objRect.Intersects( object2->GetBoundingRect(), &objRect );
}



I'm sure everything is in order. There must be something I'm missing though, the compiler doesn't make mistakes.
Was This Post Helpful? 0
  • +
  • -

#4 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 762
  • View blog
  • Posts: 2,214
  • Joined: 20-March 10

Re: Why am I getting this error? (Un)resolved External Symbol

Posted 12 December 2012 - 10:58 PM

You dont seem to be,

including Quadtree.h in

Game.cpp

Best Wishes

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#5 GryphonClaws  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 37
  • Joined: 09-December 12

Re: Why am I getting this error? (Un)resolved External Symbol

Posted 12 December 2012 - 11:15 PM

It's included in Game.h
Just to make sure, I included it in the .cpp file and it's still giving the same error.
Was This Post Helpful? 0
  • +
  • -

#6 GryphonClaws  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 37
  • Joined: 09-December 12

Re: Why am I getting this error? (Un)resolved External Symbol

Posted 12 December 2012 - 11:26 PM

Hmmm not sure why this isn't working but I decided to remove the declaration from Game.h and declare and init in Game.cpp and now it compiles. Thanks for reading and the responses!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1