Sign in to follow this  
agm_ultimatex

LNK2001 error

Recommended Posts

agm_ultimatex    191
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
CodeCriminal    290
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this