Здравствуйте, andrey.desman, Вы писали:
M>>Виноват
M>>И что делать, если деструктор есть? Кроме как явно описать конструктор/оп= перемещения?
AD>Явно задекларировать его как default.
Так работает, да.
AD>Но вроде как у тебя все равно же явные телодвижения нужны на перемещение? Timer id переместить в новый объект, в старом занулить, не?
Точно, мой косяк
Кстати, а есть рекомендации ведущих собаководов, как правильно писать move ctor/move op=?
UPD
Написал так:
| | Скрытый текст |
| | struct WindowTimerImpl : public IWindowTimer
{
HWND hWnd = 0;
UINT_PTR idTimerEvent = 0;
timeout_t timerTimeoutMs = 0;
bool running = false;
//WindowTimerImpl(HWND h, UINT_PTR id) : hWnd(h), idTimerEvent(id) {}
WindowTimerImpl(HWND h, UINT_PTR id, timeout_t timeoutMs, bool bRunning) : hWnd(h), idTimerEvent(id), timerTimeoutMs(timeoutMs), running(bRunning)
{
if (running)
{
restart();
}
}
WindowTimerImpl(WindowTimerImpl&& other)
: hWnd (std::exchange(other.hWnd, (HWND)0))
, idTimerEvent (std::exchange(other.idTimerEvent, 0u))
, timerTimeoutMs(std::exchange(other.timerTimeoutMs, 0u))
, running (std::exchange(other.running, false))
{
}
WindowTimerImpl& operator=(WindowTimerImpl&& other)
{
hWnd = std::exchange(other.hWnd, (HWND)0);
idTimerEvent = std::exchange(other.idTimerEvent, 0u);
timerTimeoutMs = std::exchange(other.timerTimeoutMs, 0u);
running = std::exchange(other.running, false);
return *this;
}
};
|
| | |
Но, по идее, у меня есть значения по умолчанию, или как такая inplace инициализация называется? По идее, mctor = default и наличия такой инициализации должно хватать для генерации того, что мне пришлось ручками натоптать, не?