SFML community forums
Help => System => Topic started by: Xenavar on August 27, 2010, 06:10:26 am
-
Hello,
I have been trying to call a thread in a class using a function from an inherited class like this:
sf::Thread Thread(&Attacks[Index].Start_Animation());
However, I get the following error:
C:\Users\Steven\Desktop\RPG\PC.cpp|225|error: request for member `Start_Animation' in `((PC*)this)->PC::Attacks[((int)Index)]', which is of non-class type `Attack*'|
Function works when its not in a thread, such as:
Attacks[Index].Start_Animation()
The 2 classes look like this (A caracter has x number of attacks)
class Attack
{
protected:
public:
void Start_Animation(void* UserData);
};
class PC
{
protected:
Attack *Attacks[10];
public:
}
Any suggestion? I am pretty sure I am just missing a coma or something.
-
You can only use non-member functions taking a void* as argument.
Read the tutorial for more details.
-
sf::Thread Thread(&Attacks[Index].Start_Animation());
However, I get the following error:
C:\Users\Steven\Desktop\RPG\PC.cpp|225|error: request for member `Start_Animation' in `((PC*)this)->PC::Attacks[((int)Index)]', which is of non-class type `Attack*'|
You are starting a thread using what Start_Animation returns (which is a Attack pointer) and not the function itself. Skip the extra ()
-
Skip the extra ()
This is not enough, C++ is not that flexible, only this kind of function will work
void thread_func(void*);
-
You could simply wrap the member function though:
void callmember(void* number) {
Attacks[*(static_cast<int*>(number))].Start_Animation();
}
And then call callmember as a thread.[/code]
-
Thank you for your replys, its all working except when I try to call the thread in class "PC" I have the following error:
C:\Users\Steven\Desktop\RPG\PC.cpp|226|error: no matching function for call to `sf::Thread::Thread(void (PC::*)(void*, int), short int&)'|
Code is:
void PC::Handle_event(sf::Event Event, sf::RenderWindow &App)
{
sf::Thread Thread(&PC::Start_Animation, Index); <----------------------
}
void PC::Start_Animation(void* UserData, int Index)
{
Attacks[Index]->Next(Sprite,Facing);
}
At first I tryed to remove the PC:: in front of the function but it told me to put it back (meaning sf::Thread Thread(&Start_Animation, Index); doesn't work either)
What am I missing here?
-
This is just the third time that I say it :D
The function that you pass to sf::Thread must have this prototype
void thread_func(void*);
And nothing else.
Yours is:
void PC::thread_func(void*, int);
So:
- make it a non-member function (or a static member)
- remove the int parameter
But after looking at your code I can give you a much better answer: don't use a thread for animating a sprite, this is the wrong way of doing it. You should rather update your animation in the main thread, when your main loop calls the update function of your entity (or whatever that updates its state every frame).
-
Heh, sorry for forcing you to repeat I am french and we don't use the same terms. But ive fixed my problem without using threads and its smooth.
Thank you very much again.
-
Heh, sorry for forcing you to repeat I am french and we don't use the same terms
I'm french too, and there's a french forum here ;)
http://www.sfml-dev.org/forum-fr/