2008年1月20日日曜日

代入演算子

をオーバーロードした場合、戻り値は参照にすべき。

そうしないと、以下のコードの(1),(2)のような式が成り立たなくなってしまう。

class Value {
private:
int value;
public:
Value(int value = 0) {
this->value = value;
}
int get() {
return value;
}
Value& operator=(Value& value) {
this->value = value.value;
return *this;
}
Value& operator+=(int value) {
this->value += value;
return *this;
}
};

int main(int argc, char** argv) {
Value a = 1;
Value b = 2;
Value c = 3;
Value d = 4;

c = b = a; // (1)
printf("c=%d,b=%d,a=%d\n", c.get(), b.get(), a.get());
(a = d) += 1; // (2)
printf("a=%d,d=%d\n", a.get(), d.get());

return 0;
}

2008年1月15日火曜日

画面遷移しないファイルアップロード

このページではファイルアップロードしても、画面遷移が発生してないんだけど、どうやってるのか分からなかったのでソース読んだ。
そしたら、submit時に非表示のiframe作って、そこをtargetにして、postしてた。
なるほどね。

2008年1月11日金曜日

window.onload Problem

The window.onload Problem - Solved!
によれば、

The problem is that the onload event fires after all page content has loaded (including images and other binary content). If your page includes lots of images then you may see a noticeable lag before the page becomes active. What we want is a way to determine when the DOM has fully loaded without waiting for all those pesky images to load also.

ってことで、ブラウザ毎の回避策が書いてある。

conditional compilation

http://msdn2.microsoft.com/en-us/library/121hztk3(vs.71).aspx

こんな事ができるのね、、、

if (1 /*@cc_on -1 @*/) alert("not ie");

実践 パケット解析

欲しい。。。
http://www.oreilly.co.jp/books/9784873113517/toc.html

7-9章のケーススタディが面白そう。

追記(2008/1/27)
立ち読みしたけど、期待した程ではなかった。だから買わないことにした。

2008年1月6日日曜日

関数属性の宣言

__attribute__((constructor)) みたいな、関数属性の宣言って知らなかった。

asmlinkage

http://kernelnewbies.org/FAQ/asmlinkage
「すべての引数がスタックで渡されることが保証される」ということかな?