TheClass
contains a std::mutex
(and many other members).
I want to write a function which creates this class so I only have to set the constructor arguments in one place:
TheClass CreateTheClassInstance()
{
TheClass tc("specific args", specific_int);
return tc;
}
then other classes requiring an instance of TheClass
can call CreateTheClassInstance()
to obtain one:
SomethingElse() : _the_class(CreateTheClassInstance())
{
}
TheClass _the_class;
Unfortunately because TheClass
has a std::mutex
, member CreateTheClassInstance()
won’t compile because the copy constructor is implicitly deleted.
I tried using std::move()
but that too doesn’t work.
Is there any other way I can achieve a factory method?