I have some class(Window) without copy constructor (it’s private). I can’t understand how to init var of this class in my own class:
class MyClass
{
Window obj; // Hasn't copy constructor
public:
void init()
{
obj = Window(/* constructor params */); // [error]
obj(/* constructor params */); // [error]
}
}
Error 1: initializing argument 1 of ‘Window::Window(WindowHandle, const sf::WindowSettings&)’
Error 2: ‘NonCopyable& NonCopyable::operator=(const NonCopyable&)’ is private
But it works in this way:
Window obj(/* constructor params */);
Your
MyClassneeds a constructor to initialize theobjmember.If you need the
init()function, and theWindowobject provides its owninit()function of some sort, you can do this:If the
Windowclass does not have anything like aninit()function, you can use the heap (not recommended unless you absolutely have to):If the
Windowclass declares a private copy constructor and/or copy assignment operator, then you cannot assign a newWindowinstance toobj.