Archive for the ‘C++ 求生筆記’ Category

Macro 小技巧 [C++ 求生筆記]

Wednesday, April 9th, 2008

假如要寫出以下的Macro[1. 當然最好是用template,這個只是例子]: #define SWAP(a, b) \ temp = (a); \ (a) = (b); \ (b) = temp; float temp; float a = 10; float b = 20; // case 1 SWAP(a,b); // Correct. // case 2 if( a > 10) { ...

Keyword Static (Function) [C++ 求生筆記]

Monday, April 7th, 2008

有一些 C 的語法,在 C++ 的程序員相對少用。但就是因為這個原因,有時就會忽略了。 假設我們有一個Header檔 Foo.h: static void f1() { std::cout

Keyword Template [C++ 求生筆記]

Friday, April 4th, 2008

作為一個C++程序員,C++ 這語言本身的認識,是很重要的。有時,有一些語法和守則,因為太少接觸和應用,所以會完全忽略了。希望這個C++ 求生筆記系列,可以給大家參考和交流一下。 今天先說一下這個keyword:template,一個簡單的使用如下: template < typename T > class Foo { public: template R Func() { ...