Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 06:47

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Threads in Class

Discussion on Threads in Class within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
ernilos's Avatar
 
elite*gold: 20
Join Date: Jan 2012
Posts: 766
Received Thanks: 645
Threads in Class

Hi guys! I'm wrritting a Class, i have that
Code:
class Player
{
private:
	/*......*/
	void UserThread(){
	std::cout << "Player connected and started the Thread!" << std::endl;
	};
	/*......*/
public:
	/*......*/
	void StartThread()
	{_beginthread(this->UserThread, 0,0);};
	/*......*/
};
Ok, i need start the void UserThread() as a thread, i tryed with _begin thread but give me a 'argument error' :C
ernilos is offline  
Old 01/23/2013, 17:01   #2



 
+Yazzn's Avatar
 
elite*gold: 420
Join Date: Jan 2012
Posts: 1,082
Received Thanks: 1,000
Code:
class Player
{
private:
	static void thread(void *arg)
	{
		Player *_this = static_cast<Player *>(arg);

		//
		// We need the this ptr to call member functions etc.
		// For example:
		// _this->foo();
		//

		std::cout << "Player connected and started the Thread!" << std::endl;
	}

	//
	// void foo()
	// {
	//     ...
	// }
	//

public:
	void startThread()
	{
		_beginthread(thread, 0, this);
	}
};
+Yazzn is offline  
Thanks
1 User
Old 01/23/2013, 18:28   #3
 
ernilos's Avatar
 
elite*gold: 20
Join Date: Jan 2012
Posts: 766
Received Thanks: 645
Works Perfectly, thanks^^
Close pls:3
ernilos is offline  
Reply


Similar Threads Similar Threads
what is the best class to grind metin2 yang(class selection guide for newbies)
07/07/2012 - Metin2 - 1 Replies
Again, I am using Enligsh. So if you cant read it well, just turn to google online translation. If i am supposed to say or answer what is the best class for grinding metin2 yang in Metin2, of course the most efficiently, i strongly recommand the Warrior, and promote to Sword Warrior at level 5. This class has both high defense and attack, as well as great area attack skill and control skill(I mean the stun skill). I recommend the BM sura as your second choice,because he has the sweetest...



All times are GMT +1. The time now is 06:47.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.