2008-05-27から1日間の記事一覧

汎用クラス

C++

とりあえず使ってみる。 「return 0;」が気になるな… #include <iostream> using namespace std; template <class T> class Stack { private: T *stack; int size; int tos; public: Stack(int size); ~Stack(); bool push(T x); T pop(); bool empty(); }; template <class T> Stack<T>::St</t></class></class></iostream>…

IE7が気に入っている

WEB

容量の少ないX40にいくつもブラウザを入れたくないので、IE7を使うようにしているが、なんとなく気に入ってしまった。 特に以下のインタフェースが気に入っている。 クイックタブ タブの左隅にあるボタンを押すと… タブ画面をタイル状に並べてくれる。 フィ…

例外の制限

C++

VCだとサポートされず。(コンパイルエラーにはならず、無視される) #include <iostream> using namespace std; void func() throw(int) { throw 0L; } int main() { try { func(); } catch(...) { } } $ g++ -g foo.cpp -o foo && ./foo Hangup</iostream>

terminateとunexpected

C++

#include <iostream> using namespace std; void func() throw(int) { throw 0L; } void uhandler() { cout << "uhandler()" << endl; } void thandler() { cout << "thandler()" << endl; exit(1); } int main() { set_unexpected(uhandler); set_terminate(thandler)</iostream>…

例外を上に投げる

C++

「...」で受け取っても上に投げれる、と。 #include <iostream> using namespace std; void foo() { throw "error"; } void bar() { try { foo(); } catch (...) { cout << "error at foo()" << endl; throw; } } int main() { try { bar(); } catch (char *e) { cout <</iostream>…

new(nothrow)

C++

VCでもビルドできた。 bad_allocはどっかでハンドルすべきなのかなぁ… #include <iostream> using namespace std; int main() { int *i = new(nothrow) int; }</iostream>

template、template

C++

#include <iostream> using namespace std; template <class T> class Foo { T x; public: Foo(T x); void show(); template <class TT> void func(T x, TT y); }; template <class T> Foo<T>::Foo(T x) : x(x) {} template <class T> void Foo<T>::show() { cout << x << endl; } template <class T> template <class TT> …</class></class></t></class></t></class></class></class></iostream>

typeidを使ってみる

C++

#include <iostream> #include <typeinfo> using namespace std; template <class T> class Foo { public: void show() { cout << typeid(Foo<T>).name() << endl; } }; int main() { Foo<int> foo; Foo<Foo<int>> bar; cout << typeid(foo).name() << endl; cout << typeid(bar).name() << endl; return 0;</foo<int></int></t></class></typeinfo></iostream>…

dynamic_castとvirtual

C++

http://rararahp.cool.ne.jp/cgi-bin/lng/vc/vclng.cgi?print+200404/04040017.txt うーん、わかるようなわからないような。 確かに、virtualなメンバ関数を持っていないような基本クラスを派生クラスにキャストする状況は少ない気がする。 どっかに、仕様な…

link: Deep C++ 演算:static_cast

C++

http://msdn.microsoft.com/ja-jp/library/cc440191(VS.71).aspx 酔った頭だとぜんぜん理解できない…

Javaの黒魔術

Javaの黒魔術の最たるものってなんだろなーと考えたことがあって、BCELみたいなバイトコードを直接いじっちゃうのがそれではないかと思ったりした。 もちろんRubyだって動的にクラスをいじることはできるけど、動的な型付けの言語のそれとは少し性質が違うよ…