-2
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.

  • @0x499602d2 [So we're still using it?](http://meta.stackoverflow.com/questions/265806/should-regular-faq-style-answers-be-closed-as-too-broad) ;-) ... – πάντα ῥεῖ Aug 28 '14 at 03:29
  • The burden of proof is actually always on the OP to ask quality questions, and the community will close / mark as duplicate questions that don't meet site standards. While I'm willing to believe you, your edit simply *claims* the questions aren't related, without providing any actual distinction or clarification. I'll happily vote to re-open if you can help me understand why they're different. – dimo414 Aug 28 '14 at 04:08

1 Answers1

0

Most likely, main.obj was built against the older player header file and so it still references the version of the method that returns void. The linker does not find this symbol since the player.obj file no longer contains it.

Remove all of your .obj files (the "clean" command in your IDE should do this) and rebuild to make sure that it uses the information in the updated header file.

cdhowie
  • 158,093
  • 24
  • 286
  • 300
  • Thanks for your answer! Sadly, neither cleaning or rebuilding the project worked for me. I probably should have mentioned in the OP that I tried this. – Runny Babbit Aug 28 '14 at 03:19
  • @RunnyBabbit Then delete the build output directory by hand. The error clearly shows that it is looking for the `void` method. If you changed it to `bool` in the implementation file **and** in the header file then you would not get this build error as long as you were building from scratch. – cdhowie Aug 28 '14 at 04:37