// #define による定数定義の代わりに、static constメンバ変数を使用する。 // VC6(SP4)でもコンパイルを通す方法。 #include <iostream> using namespace std; class foo { public: static int mul( int a, int b ); static int get_i( ); private: const static int i_ ; // ここで初期化できない(VCバグ) }; int foo::mul( int a, int b ) { return a * b; } int foo::get_i( ) { return i_; } const int foo::i_ = 20; // ここでしてやる int main() { int c = foo::mul( 2, 4 ); cout << "c = " << c << endl; int i = foo::get_i(); cout << "i = " << i << endl; return 0; } /* 本当は、static const メンバ変数はクラス宣言内で初期化できるんだからね。 */ // end of file