Background
I have a chunk of code with the following characteristics:
IO
class which is non-copyable due to astd::ifstream
memberFoo
class which has a NamedConstructor, that likes to call a copy constructor
Question
Is there a pattern I can use where I keep the NamedConstructor in Foo (or something equivalent), but I still can insert non-copyable members into Foo?
I welcome C++11 features/solutions.
Test Code
#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();
}