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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Trampampam

Pages: [1]
1
System / Smth wrong with getting parameter in function for sf::Thread
« on: November 11, 2012, 11:43:11 am »
I'm trying to get char * made in such way:
#include <string>
#include <cstring>
...
void smthInThread(void *UserData){
//some everlasting loop from which the thread "threadEval" will call
while(true){
  //getting std::string str from console
  std::string str;
  std::getline(std::cin, str);

  //getting cstring cstr from str
  char * cstr;
  cstr = new char [str.size()+1];
  strcpy(cstr,str.c_str());

  //passing cstr into evalInThread where problem is
  sf::Thread threadEval(&evalInThread, &cstr);
  threadEval.Launch();
}
}

//!function where problem is:
void evalInThread(void *UserData){
  //That's in tutorial:
  // Cast the parameter back to its real type
  //  MyClass* Object = static_cast<MyClass*>(UserData);

  //That's what I'm doing:
  char * evalString = static_cast<char *>(UserData);
  std::cout << evalString; //!! This return wrong string !!
}
 

The problem is that I can not cast the parameter of char * back to its real type, although I do all as in tutorial written
What I'm doing wrong?
Or, maybe, there's another way to get parameter of such type inside threaded function?

btw: I am using SFML ver 1.6 'cause I need stable version

Pages: [1]
anything