C++

配列の参照を返す

C++で配列の参照を関数の返り値にするにはどうすればいいかを考えていた. typedefで型を定義してやるとできるみたい. arrayを使え,っていう話もある. #include <iostream> #include <iterator> #include <array> using namespace std; struct A { A() : v_(1) {} A(int v) : v_(v) {</array></iterator></iostream>…

moveが気になったので

魔導書Vol.1で触れられていたC++0xのmoveが気になったので,ちょっと書いてみた. #include <iostream> using namespace std; struct Foo { int v_; Foo() : v_(0) { cout << "ctor (default) for " << this << endl; } Foo(int a) : v_(a) { cout << "ctor (with int)</iostream>…

アドレス値を数値として演算したいとき

stdint.hに定義されているintptr_tまたはuintptr_tを使う.

error: explicit template specialization cannot have a storage class

gcc43を使ってみたら怒られたのでメモ: GCC 4.3 Release Series ― Porting to the New Tools - GNU Project - Free Software Foundation (FSF) Explicit template specialization cannot have a storage classSpecializations of templates cannot explicitl…