廢話就不多說了
直接提供網址:
http://www.kfsoft.info/article-43-11--%E8%99%95%E7%90%86Activity-Result.html
寫得滿好的
希望因為我多加了一個inlink
可以讓他的blog被更多人看到XDD
2011年12月28日 星期三
[Android] thread, join
join的解釋如下:
來源資料:http://developer.android.com/reference/java/lang/Thread.html
Blocks the current Thread (
Thread.currentThread() ) until the receiver finishesits execution and dies. | |
Blocks the current Thread (
Thread.currentThread() ) until the receiver finishesits execution and dies or the specified timeout expires, whatever happens first. | |
Blocks the current Thread (
Thread.currentThread() ) until the receiver finishesits execution and dies or the specified timeout expires, whatever happens first. |
2011年12月22日 星期四
[C++] header, static and compilation
自己做研究寫c++時
如果檔案一多起來
Makefile就變得很重要
通常程式還算小的話
只要搭配#include guards用#ifndef, #define, #endif
並把每個class的宣告(Prototypes, Definition)寫在.h檔
把實作的部分寫在.cpp檔裡
用makefile把所以class都分別compile在用link起來就沒啥問題了
但class小的時候
把宣告跟實作分別寫在.h和.cpp檔真的頗為麻煩
尤其當class只是簡單container沒啥功能時
撰寫cpp檔更是顯得很冗又很繁瑣
用#include其實就是把檔案先直接嵌入
再行編譯
所以如果有任何的初始化(initialization)出現在.h檔裡
那該.h檔就只能被一個.cpp程式引用
因為當有同時有兩個.cpp引用的該header
則兩個cpp檔都會做相同的初始化動作
這會導致最後一步link所有cpp檔編譯完的.o檔時
產生變數名稱衝突的問題
簡單來說就是相當於一樣的變數名被宣告兩次
避免發生這問題有幾個方法:
1) 不要在.h檔裡初始化,這樣就不會在多個檔案被allocated
2) 如果一定要在.h檔裡初始化,那就確保該.h檔只被一個.cpp檔引用
參考來源:
http://stackoverflow.com/questions/2470737/why-cant-initialize-the-static-member-in-a-class-in-the-body-or-in-the-header-f
如果檔案一多起來
Makefile就變得很重要
通常程式還算小的話
只要搭配#include guards用#ifndef, #define, #endif
並把每個class的宣告(Prototypes, Definition)寫在.h檔
把實作的部分寫在.cpp檔裡
用makefile把所以class都分別compile在用link起來就沒啥問題了
但class小的時候
把宣告跟實作分別寫在.h和.cpp檔真的頗為麻煩
尤其當class只是簡單container沒啥功能時
撰寫cpp檔更是顯得很冗又很繁瑣
用#include其實就是把檔案先直接嵌入
再行編譯
所以如果有任何的初始化(initialization)出現在.h檔裡
那該.h檔就只能被一個.cpp程式引用
因為當有同時有兩個.cpp引用的該header
則兩個cpp檔都會做相同的初始化動作
這會導致最後一步link所有cpp檔編譯完的.o檔時
產生變數名稱衝突的問題
簡單來說就是相當於一樣的變數名被宣告兩次
避免發生這問題有幾個方法:
1) 不要在.h檔裡初始化,這樣就不會在多個檔案被allocated
2) 如果一定要在.h檔裡初始化,那就確保該.h檔只被一個.cpp檔引用
參考來源:
http://stackoverflow.com/questions/2470737/why-cant-initialize-the-static-member-in-a-class-in-the-body-or-in-the-header-f
訂閱:
文章 (Atom)