Jump to content
  • Advertisement
Sign in to follow this  
agm_ultimatex

LNK2001 error

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

The problem is probably staring at me right in the face. I feel like I should be able to solve this, but no luck ;). Im just starting to put a pong clone together. I have my Piece class which has all the good x and y values. In the main method, I have some starter SFML stuff to render the ball on the screen. Just going to get a bouncing ball working first, then I'll worry about the player pieces. The Linker error is as follows: Error 1 error LNK2001: unresolved external symbol "public: __thiscall Piece::~Piece(void)" (??1Piece@@QAE@XZ) main.obj Here is my source:
// Pong.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <SFML/Graphics.hpp>
#include "Piece.hpp"

int _tmain(int argc, _TCHAR* argv[])
{
	sf::RenderWindow app(sf::VideoMode(800, 600, 32), "Pong Clone");
	Piece theBall(50, 50, 30, 30);
	sf::Shape squarePiece;
	
	squarePiece.AddPoint(theBall.GetX(), theBall.GetY(), sf::Color(255, 255, 255), sf::Color(255, 255, 255));
	squarePiece.AddPoint(theBall.GetRightX(), theBall.GetY(), sf::Color(255, 255, 255), sf::Color(255, 255, 255));
	squarePiece.AddPoint(theBall.GetRightX(), theBall.GetBottomY(), sf::Color(255, 255, 255), sf::Color(255, 255, 255));
	squarePiece.AddPoint(theBall.GetX(), theBall.GetBottomY(), sf::Color(255, 255, 255), sf::Color(255, 255, 255));
	squarePiece.AddPoint(theBall.GetX(), theBall.GetY(), sf::Color(255, 255, 255), sf::Color(255, 255, 255));

	while(app.IsOpened())
	{
		sf::Event e;
		while(app.GetEvent(e))
		{
			if(e.Type == sf::Event::Closed)
			{
				app.Close();
			}
			// if escape was pressed
			if((e.Type == sf::Event::KeyPressed) && (e.Key.Code == sf::Key::Escape))
			{
				app.Close();
			}
		}
		app.Draw(squarePiece);
		app.Clear();
		app.Display();
	}
	return EXIT_SUCCESS;
}

Piece.hpp:
#include "stdafx.h"
#ifndef PIECE_H
#define PIECE_H
class Piece
{
public:
	Piece(float x, float y, float sizeX, float sizeY):x(x), y(y), sizeX(x), sizeY(y){}
	~Piece();

	float GetX();
	float GetY();
	void SetX(float x);
	void SetY(float y);
	void IncrementX(float x);
	void IncrementY(float y);
	void DeincrementX(float x);
	void DeincrementY(float y);
	float GetSizeX();
	float GetSizeY();

	float GetRightX();
	float GetBottomY();
private:
	float x;
	float y;
	float sizeX;
	float sizeY;
};
#endif

Don't think you will need it, but here's Piece.cpp
#include "stdafx.h"
#include "Piece.hpp"

float Piece::GetX()
{
	return x;
}

float Piece::GetY()
{
	return y;
}

void Piece::SetX(float x)
{
	Piece::x = x;
}

void Piece::SetY(float y)
{
	Piece::y = y;
}

void Piece::IncrementX(float x)
{
	Piece::x += x;
}

void Piece::IncrementY(float y)
{
	Piece::y += y;
}

void Piece::DeincrementX(float x)
{
	Piece::x -= x;
}

void Piece::DeincrementY(float y)
{
	Piece::y -= y;
}

float Piece::GetSizeX()
{
	return sizeX;
}

float Piece::GetSizeY()
{
	return sizeY;
}

float Piece::GetRightX()
{
	return x + sizeX;
}

float Piece::GetBottomY()
{
	return y + sizeY;
}

Share this post


Link to post
Share on other sites
Advertisement
get rid of your destructor, its unnecessary.
The reason you are getting the error is because you haven't defined the destructor in the .cpp file of Piece (if 'defined' is the right word, currently having a brain fart)
i.e.


Piece::~Piece( )
{
// body of piece destructor
}


Add the above if you feel a destructor is necessary..

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!