|
Advance Member
|
寫 C/C++ 程式時,常常忘記大中小括號而 compile 錯誤嗎?
常常寫出一大堆 memory leak (new 了某些東西,卻忘記 delete) 嗎?
在這裡提供一個簡單的方法...
宣告一個 class 或是 function 時, 直接打上
class AClass {}
或是
void AFunction(int cX, int cY) {}
然後再跳回去斷行:
class AClass {
}
...
void AFunction(int cX, int cY) {
}
這樣就不會一天到晚忘括號啦~至少可以有效解決大部份這種問題~
new - delete 也是一樣!只要一 new 出某個東西,馬上把對應的 delete 寫好:
char* buff = new char[256];
delete [] buff;
然後再回到兩行之間加入程式碼:
char* buff = new char[256];
//Do something to the buff...
delete [] buff;
小小心得,供各位參考~
|