2008-05-16から1日間の記事一覧
Cの標準ライブラリはnamespace stdに定義されてるのかなぁ? #include <cstdio> int main() { printf("Hello, C++\n"); std::printf("Hello, C++\n"); }</cstdio>
通常、ストリーム入出力はバッファリングされており、『バッファが満杯になった。』あるいは『バッファの掃き出しが指示された。』などを機会に出力が行われます。endl処理子を出力すると、改行されるだけでなく、バッファのフラッシュも行われます。 バッフ…
変数初期化時の代入では、コンストラクタと代入演算子のどちらが呼ばれるのか気になったので、実験してみた。 #include <iostream> using namespace std; #define DEBUG(s) do { cerr << (s) << endl; } while(false); class Foo { private: int i; public: Foo(); Foo</iostream>…
初期化子ってコンストラクタの呼び出しなのかな? #include <iostream> using namespace std; #define DEBUG(s) do { cerr << (s) << endl; } while(false); class Bar { public: Bar(); Bar(int i); Bar(int i, int j); }; Bar::Bar() { DEBUG("Bar::Bar()"); } Bar::</iostream>…
#include <iostream> using namespace std; #define DEBUG(s) do { cerr << (s) << endl; } while(false); class Foo { private: int i; public: Foo(); ~Foo(); int value(); }; Foo::Foo() : i(100) { DEBUG("Foo::Foo()"); } Foo::~Foo() { DEBUG("Foo::~Foo()"); }</iostream>…
#include <cstdio> union Foo { Foo(short i); void show(); private: short i; unsigned char cs[2]; }; Foo::Foo(short i) : i(i) {} void Foo::show() { printf("l:%x h:%x\n", cs[0], cs[1]); } int main() { union { short i; unsigned char cs[2]; }; i = 0xAB</cstdio>…