c++

Cheat Sheet (C/C++ const)

c++

以下は、c でも c++ でも同じ。 X(x) になってるところは全て警告orエラーになる。 void foo(void*x){} #define C const #define X(x) /* x */ int main() { int * * p000; int * * C p001; int * C * p010; int * C * C p011; int C * * p100; int C * * C …

valgrind

c++

ある目的で, こんなテストプログラムを書いてみた. #include <iostream> #include <vector> struct X { std::vector<X*> children; X () { std::cout << "+[" << this << "]\n"; } ~X () { for( size_t i = 0; i < children.size(); ++i ){ if( children[i] ){ delete children[i];</x*></vector></iostream>…

template?

c++

下のような書き方で, 途中に出てくる template って何でしょうか? template<T,S> struct hoge { typedef typename foo<S>::bar Bar; typedef typename Bar::template xxx<T,S>::yyy zzz; }; 正解は, 以下のような文脈でテンプレートクラス(構造体)を参照するためのキーワ</t,s></s></t,s>…

this はつけるべきか

c++

C++ (や Java その他の言語)において, メンバ変数や関数のアクセスに this->をつけるべきか否か, という疑問があり, 調べてみた.this をつけるべきかどうかについてはコーディング規約や好みの問題で議論されている(た). が, 何か決定的な違いがあったような…

マイ整数

数値クラスを新しく定義し、演算子 (e.g., 加算) を定義するときの注意点について。 どうも、一時オブジェクト周りの最適化 (RVOとか) が想定していた通りには効いていない事に気づいたので、メモ。 #include <iostream> #define PP(x) do{std::cout<</iostream>