Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: multitread problem  (Read 1191 times)

0 Members and 1 Guest are viewing this topic.

catalinnic

  • Newbie
  • *
  • Posts: 19
    • View Profile
multitread problem
« on: February 28, 2019, 09:03:16 pm »
I have a problem with using threads.
I want to use the function wallai2 but when i want to use it as a parameter with reference it sents me a bunch of errors:
C:\SFML-2.5.1\include\SFML\System\Thread.inl||In instantiation of 'void sf::priv::ThreadFunctor<T>::run() [with T = void (ai::*)()]':|
C:\Users\catal\Desktop\Imp\codeblocks\txtgame\src\map1.cpp|221|required from here|
C:\SFML-2.5.1\include\SFML\System\Thread.inl|39|error: must use '.*' or '->*' to call pointer-to-member function in '((sf::priv::ThreadFunctor<void (ai::*)()>*)this)->sf::priv::ThreadFunctor<void (ai::*)()>::m_functor (...)', e.g. '(... ->* ((sf::priv::ThreadFunctor<void (ai::*)()>*)this)->sf::priv::ThreadFunctor<void (ai::*)()>::m_functor) (...)'
And
sf::Thread t1(&wallai2); goes to this: include\Joc.h|110|error: expected identifier before '&' token|
Down are the ensential files.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: multitread problem
« Reply #1 on: February 28, 2019, 11:30:01 pm »
It's part of a class, so you have to pass the class instance. See also the API documentation: https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Thread.php

But I'm pretty sure, you don't actually want/need threading. It will add a lot more complexity to your application with little to no gain. Plus, unless you're very experienced with parallel programming, you'll be making lots of synchronization mistakes, which will not be trivial to catch.

Btw. your code is nearly unreadable. You should use names that say something about the object. "Wall1" or "Wall2" don't say anything outside of your own head. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/