C++ SFML std::thread doesn't work

by Alexander   Last Updated January 12, 2018 18:05 PM

(global)

class lasers
{
public:
    Sprite sLaser;
    int ok2=0;
    void fire(Texture &t5, FloatRect bbBG, Vector2f pP)
    {
        if(ok2!=1)
        {
        sLaser.setTexture(t5);
        sLaser.setOrigin(1,-705);
        sLaser.setPosition(pP.x+20.5,pP.y+645);
        sLaser.scale(0.1f,0.1f);
        ok2=1;
        }

        while(sLaser.getGlobalBounds().intersects(bbBG))
        {
        sLaser.move(0,-2);
        sleep(milliseconds(10));
        }


    }
};     

(main)

lasers zxcv;

................

    if(Keyboard::isKeyPressed(Keyboard::Space))
    {
        thread t1(&lasers::fire, &zxcv, t5, boundingBoxBORDER, sPlayer.getPosition());
    }

................

(errors)

||=== Build: Debug in GAME (compiler: GNU GCC Compiler) ===|

main.cpp||In function 'int main()':|

\functional||In instantiation of 'struct std::_Bind_simple, sf::Vector2)>(lasers, sf::Texture, sf::Rect, sf::Vector2)>':|

\thread|137|required from 'std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (lasers::*)(sf::Texture&, sf::Rect, sf::Vector2); _Args = {lasers&, sf::Texture&, sf::Rect&, const sf::Vector2&}]'|

\functional|1665|error: no type named 'type' in 'class std::result_of, sf::Vector2)>(lasers, sf::Texture, sf::Rect, sf::Vector2)>'|

\functional|1695|error: no type named 'type' in 'class std::result_of, sf::Vector2)>(lasers, sf::Texture, sf::Rect, sf::Vector2)>'| ||=== Build failed: 2 error(s), 4 warning(s) (0 minute(s), 1 second(s)) ===|

(Question)

I'm not sure what I'm doing wrong, as this is my first time working with threads(for a school project). I've looked at several examples including ones with classes, but somehow I haven't yet managed to make this work.

I basically want to make sprites which start from a point and go upwards until they hit something and disappear. So I figured making a class provides me with infinite functions and sprites for that, and I can just use some sequence in the main to create as many objects as I wish. Perhaps this isn't the best approach, but I think it would work if I manage to make the thread work.

Could someone give me some advice on how to get rid of the last two errors from above and finally make the thread work? Thank you.



Related Questions