You should change your function to not accept LPVOID. NextFreeSpace should have a type. That's what you'll use in your function. That is, if you can. C++ preserves types, unlike C.
Yes, I had this because of CreateThread but now its not needed well looks nice
Btw what is returned as thread in :
What type has this variable and what it represent?Code:boost::thread thread(&ClientHandler::ServeClient, CHandler, NextFreeSpace);
I take it Clients is some array of boost::thread, then?
In such case, there might be two solutions:
boost::thread thread(...);
std::swap(Clients[NextFreeSpace].thread, thread);
Or
boost::thread thread(...);
Clients[NextFreeSpace].thread = std::move(thread);
With swap it says me its const boost and to move i have to include sth or ? It says its not member of std.
I have struct TClient which is info about connected client. I have also array of TClient named Clients. I need to store thread or pointer into struct too.
It sounds like one Clients[NextFreeSpace].thread is not assignable (it's const)?
Yes, std::move requires <utility> and C++0x.
Here is an example which works:
If your code doesn't work, then I can only assume that you cannot assign to Clients thread due to it being const. Code to demonstrate the problem perhaps?Code:#include <boost/thread.hpp> #include <algorithm> class A { public: void foo(int) {} }; int main() { A a; boost::thread thread(&A::foo, a, 0); boost::thread thread2; std::swap(thread2, thread); return 0; }
I have something ..........ed up i guess.. even your example don't work.
C:/Program Files (x86)/Boost-1.41.0/include/boost-1_41/boost/thread/detail/thread.hpp: In function `void std::swap(_Tp&, _Tp&) [with _Tp = boost::thread]':
Units/ClientHandler.cpp:124: instantiated from here
C:/Program Files (x86)/Boost-1.41.0/include/boost-1_41/boost/thread/detail/thread.hpp:108: error: `boost::thread::thread(boost::thread&)' is private
C:/Dev-Cpp/include/c++/3.4.2/bits/stl_algobase.h:130: error: within this context
C:/Program Files (x86)/Boost-1.41.0/include/boost-1_41/boost/thread/detail/thread.hpp:109: error: `boost::thread& boost::thread:perator=(boost::thread&)' is private
C:/Dev-Cpp/include/c++/3.4.2/bits/stl_algobase.h:131: error: within this context
C:/Dev-Cpp/include/c++/3.4.2/bits/stl_algobase.h:132: error: passing `const boost::thread' as `this' argument of `boost::thread:perator boost::detail::thread_move_t<boost::thread>()' discards qualifiers
Can u upload fixed stl_algobase.h? I guess it have not fixed problems.
Last edited by kargo; 03-15-2011 at 03:17 PM.
Sorry to intrude here, while you are in the middle of something..., but,
Kargo, you mentioned that:
1) you are using Dev-C++,
2) OS = Win7
1) what version of Dev-C++ are you using ?
2) have you gotten Dev-C++ to compile any program ?
3) where is the working folder where your project is located ?
4) when you compile, what does your complete compile log say ?
I ask these questions because Dev-C++ release 4.9.9.2 is the latest release of Dev-C++ and it dates back to 2005.
Dev 4.9.9.2 worked on XP (with caveats) and is know to have problems working on Vista and may not work at all on Win-7 .
Unfortunately, Colin LaPlace has abandoned further development on DevC++
That's why I ask question #2.
#3 is of particular importance too.
Have you read the "Read this before..." at the Dev-C++ forum:
SourceForge.net: Dev-C++: Topics for Bloodshed Software Forum
It does explain some of the many issues and problems of using Dev-C++.
Also, Dev-C++ is using an old version of GCC.
Just a thought.
Last edited by Steve A.; 03-15-2011 at 04:06 PM.
Old version of GCC sounds bad. Perhaps it's time to upgrade. The easiest solution I can think of is Code::Blocks + the mingw compiler. That should get you started on using C++0x.
You might also try
Clients[NextFreeSpace].thread.swap(thread);
or
Clients[NextFreeSpace].thread = boost::move(thread);
Originally Posted by KargoYes,Originally Posted by Elysia
you can't simply use Dev-C++ with a newer version of GCC, it doesn't seen to work that way.
Dev-C++ (the IDE) is closely bound to that version of GCC.
Code::Blocks with MingW is a better option at this point.
I only use Dev-C++ for testing legacy code on an XP.
Where the issues and caveats are know to me and I can control them.
Unless you have Dev-C++ working, flawlessly, you may be beating a dead-horse.
Last edited by Steve A.; 03-15-2011 at 04:08 PM.
Last edited by kargo; 03-16-2011 at 03:01 AM.
No i don't but found solution :
No i don't but found solution :Code:#define _WIN32_WINNT 0x501
Including is ........ing me off :PCode:#define _WIN32_WINNT 0x501
Share.hpp
NetworkHandler.hppCode:#ifndef SHARE_H #define SHARE_H #ifndef NETWORK_HANDLER_H #include "NetworkHandler.hpp" #endif #ifndef CLIENT_HANDLER_H #include "ClientHandler.hpp" #endif #include <windows.h> #include <winsock2.h> #include <ws2tcpip.h> #include <stdio.h> #include <iostream> #include <boost/thread/thread.hpp> typedef BYTE PCK[65000]; typedef PCK *PPCK; typedef BYTE Key16[16]; NetworkHandler NHandler; //<----------- ERROR : NetworkHandler does not name a type #endif
ClientHandler.hppCode:#ifndef NETWORK_HANDLER_H #define NETWORK_HANDLER_H #include "share.hpp" class NetworkHandler { private: bool StartWSA(); bool InitSock(); bool CreateSock(); bool BindSock(); bool SetListener(); public: SOCKET ListenSocket; // NetworkHandler(){}; // ~NetworkHandler(){}; bool Init(); }; #endif
Code:#ifndef CLIENT_HANDLER_H #define CLIENT_HANDLER_H #include "share.hpp" class ClientHandler { private: // public: ClientHandler(); ~ClientHandler(){} void StartListen(); // DWORD WINAPI ServeClient(LPVOID lpParam); DWORD WINAPI ServeClient(int IDs); //<-------------- ERROR : DWORD does not name a type DWORD WINAPI WaitClients(PVOID pvParam); //<---------------- SAME }; #endif
Last edited by kargo; 03-16-2011 at 05:26 AM.