class mob;
class player
{
public:
sf::RectangleShape rect;
float bottom, left, right, top;
player(sf::Vector2f position, sf::Vector2f size, sf::Color color);
void update();
void collision(mob M);
};
Collision definition:
void player::collision(mob M)
{
if(right < M.left)
rect.setPosition(M.left, rect.getPosition().y);
}
I had made the collision function a bool in previous builds so that it would return true or false. Well, after testing it as a bool, I decided to make it a void. However, as soon as I made it a void, I get this error:
1>main.obj : error LNK2001: unresolved external symbol "public: bool __thiscall player::collision(class mob)" (?collision@player@@QAE_NVmob@@@Z)
1>C:\SFML_Project\Release\SFML_Project.exe : fatal error LNK1120: 1 unresolved externals
Also, if necessary, you can find the declaration here:
int main()
{
sf::RenderWindow Window;
Window.create(sf::VideoMode(800,600),"SFML Project");
player Cplayer(sf::Vector2f(10,10), sf::Vector2f(32,32), sf::Color::Red);
mob Cmob(sf::Vector2f(368,284), sf::Vector2f(64,32), sf::Color::Blue);
Window.setKeyRepeatEnabled(true);
while(Window.isOpen())
{
sf::Event Event;
while(Window.pollEvent(Event))
{
switch(Event.type)
{
case sf::Event::Closed:
Window.close();
break;
/*case sf::Event::LostFocus:
std::cout << "Window lost focus!" << std::endl;
break;*/
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
Cplayer.rect.move(0, -0.2);
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
{
Cplayer.rect.move(0, 0.2);
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
Cplayer.rect.move(0.2, 0);
}
else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
Cplayer.rect.move(-0.2, 0);
}
Cplayer.update();
Cmob.update();
Cplayer.collision(Cmob);
Window.draw(Cplayer.rect);
Window.draw(Cmob.rect);
Window.display();
Window.clear();
}
}
Edit:
It seems my post has been marked as a duplicate. This is a not so subtle way of shifting the burden of proof. The answers in the linked thread have nothing to do with my problem and the context drastically changes here.