2010年3月6日 星期六

解決 _beginthread 無法用於 C++ member function 的問題

剛剛發現了別人寫的 code ,同樣是解決 _beginthread 不能直接進
入 C++ member function 的問題,不過它的作法真的比我漂亮許多。
##CONTINUE##

class ThreadX
{
public:

// In C++ you must employ a free (C) function or a static
// class member function as the thread entry-point-function.

static unsigned __stdcall ThreadStaticEntryPoint(void * pThis)
{
ThreadX * pthX = (ThreadX*)pThis; // the tricky cast
pthX->ThreadEntryPoint(); // now call the true entry-point-function

// A thread terminates automatically if it completes execution,
// or it can terminate itself with a call to _endthread().

return 1; // the thread exit code
}

void ThreadEntryPoint()
{
// This is the desired entry-point-function but to get
// here we have to use a 2 step procedure involving
// the ThreadStaticEntryPoint() function.
}
}

用 while 、 vector 、 string 處理文字資料


ifstream iFile("shape_list.txt", ios::in);
if(!iFile){ exit(1); }
string line_str;
while(iFile && !iFile.eof()){
getline(iFile, line_str);
vector< string > vStr;
char* next_token;
char* pch = strtok_s(const_cast< char* > (line_str.c_str()), " ", &next_token);
while(pch != NULL){
vStr.push_back(string(pch));
cout << vStr[vStr.size()-1] << endl;
pch = strtok_s(NULL, " ", &next_token);
}
if(vStr.size() != 0){
ColorRGB co;
int id;
bool filled;
int width;
co.r = atoi(vStr[2].c_str());
co.g = ato
}
}