バックグラウンド
次の特性を持つコードのチャンクがあります。
IO
std::ifstream
メンバーのためにコピーできないクラスFoo
コピー コンストラクターを呼び出すのが好きな NamedConstructor を持つクラス
質問
NamedConstructor を Foo (または同等のもの) に保持する場合に使用できるパターンはありますが、コピーできないメンバーを Foo に挿入することはできますか?
C++11 の機能/ソリューションを歓迎します。
テストコード
#include <fstream>
class IO
{
std::ifstream m_ifs; // due to this instance, IO is not copyable
};
// #define NEXT_LINE_REQUIRES_IO_MC
class Foo
{
#ifdef NEXT_LINE_REQUIRES_IO_MC
IO m_io;
#endif
public:
static Foo NamedConstructor() {
return Foo();
}
private:
Foo() { }
};
int
main( int argv, char* argc[] )
{
Foo f = Foo::NamedConstructor();
}