2
void foo(ifstream &ifs)
{
//do something
}
int main()
{
fstream fs("a.txt", fstream::in);
foo(fs); //error, can't compile
}
上記のコードはコンパイルできません。fstream
オブジェクトでifstream &
を初期化できないようですか?私はそれをこのように行う場合:ifstreamが期待されるifstreamで
foo(static_cast<ifstream>(fs));
または
foo(dynamic_cast<ifstream>(fs));
最初は無関係のタイプです。 –
ifstreamはfstreamを拡張しません。 fstreamとifstreamの両方がistreamを拡張しますが、それ以外のものは、Oliが言ったように、無関係です。 – Corbin
@ Corbin、聖なる、私は 'ifstream'と' ofstream'が 'fstream'から派生したと考えました。 – Alcott