- 追加された行はこの色です。
- 削除された行はこの色です。
#contents
* template
- ヘッダとソースを分ける(明示的なインスタンス化)
-- http://www.fides.dti.ne.jp/~oka-t/cpplab-template-3.html
- template <typename T> typedef T1<T2<T> > T12<T> なことについて
-- [[http://www.microsoft.com/japan/msdn/library/...>http://www.microsoft.com/japan/msdn/library/default.asp?url=/japan/msdn/library/ja/jpdndeepc/htm/deep08032000.asp]]
-- とりあえず typedefのテンプレートはできない
* stringstream
- strstream の新しい版?
- #include <sstream>
* string::resize
"\0\0..." になってる?
* コンストラクタとg++(3.3.5)とboost::shared_ptrな怪しい関係
どれが悪いのかわからんが
class Foo
{
boost::shared_ptr<Qux> member;
Foo(Bar bar)
{
Foo(bar.baz());
// ここで失敗する
ASSERT(member.get());
}
Foo(Baz baz)
{
member.reset(new Qux());
}
};
init(Baz)とか言うメソッドを作って Foo(Baz)の処理をそのまま移せば問題なし。
* オーバーロードは動的ではない
callFoo は引数の表面上の方で呼ばれる。
#include <iostream>
using namespace std;
class Base
{
public:
virtual void foo()
{
cout << "Base::foo()" << endl;
}
};
class Derived : public Base
{
public:
virtual void foo()
{
cout << "Derived::foo()" << endl;
}
};
void callFoo(Base &base)
{
cout << "callFoo(Base &)" << endl;
base.foo();
cout << endl;
}
void callFoo(Derived &derived)
{
cout << "callFoo(Derived &)" << endl;
derived.foo();
cout << endl;
}
int main()
{
Base b;
Derived d;
Base *ptr = &d;
Base &ref = d;
callFoo(b);
callFoo(d);
callFoo(*ptr);
callFoo(ref);
}
callFoo(Base &)
Base::foo()
callFoo(Derived &)
Derived::foo()
callFoo(Base &)
Derived::foo()
callFoo(Base &)
Derived::foo()
* オーバーロードと デフォルト引数と char*
void foo(const std::string &str, bool flag=false);
void foo(bool flag=false);
char *p;
foo(p);
char*はstd::stringではなくboolとしてみられるので後者が呼ばれる。~
g++ 3.3.6~
* string iterator not dereferencable
VC++2005で下記のような終端チェックは string iterator not dereferencable といって落ちる。~
// だめ
*it == '\0'
// 正解
it == original.end()
ここで original が出てくるのがなんとかならんかな。
* 親クラスを引数に取るコンストラクタとコピーコンストラクタの罠
class LinkedTimer : public ITimer
{
public:
LinkedTimer(const ITimer &timer);
private:
LinkedTimer(const LinkedTimer &rhs);
};
コピーコンストラクタを潰していると、上のコンストラクタを呼んでいるつもりでコンパイルエラー。~
コピーコンストラクタを定義しなければデフォルトのコピーコンストラクタが作られてハマりそう。
* 初期化子の順番
初期化子の呼ばれる順はメンバを定義した順番であって、~
初期化子の書いてある順番ではない。