use of deleted function в c++
#include <iostream>
struct qwer
{
const int x{1};
};
qwer tt()
{
qwer xx;
return xx;
}
int main()
{
qwer qq;
qq = tt();
return 0;
}
Выдает ошибку:
qwer.cpp: In function ‘int main()’:
qwer.cpp:18:10: error: use of deleted function ‘qwer& qwer::operator=(qwer&&)’
18 | qq = tt();
| ^
qwer.cpp:4:8: note: ‘qwer& qwer::operator=(qwer&&)’ is implicitly deleted because the default definition would be ill-formed:
4 | struct qwer
| ^~~~
qwer.cpp:4:8: error: non-static const member ‘const int qwer::x’, can’t use default assignment operator
Объясните пожалуйста в чем проблема )
Ответы (1 шт):
Автор решения: Mikhailo
→ Ссылка
При присвоении по умолчанию просто выполняется почленное присвоене полей.
Но у вас поле (член) объявлено как const, т.е. присваивать ему нельзя.
Компилятор это выражает своим языком :)